Author Topic: Mechanical Design  (Read 33378 times)

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Mechanical Design
« Reply #30 on: May 20, 2011, 08:58:53 AM »
Yeah it looks like you have about got it finished. That's one very clean build.

I have attached the most recent version of the Arduino program with some slight modifications for your set up. I commented out the shift register code because you said you aren't using them, and I also implemented Bernard's code for the Adafruit motor shield.

I have also given up on trying to get the AccelStepper library to work for the time being. It works well some of the time, but there are other times that it inexplicably causes the program to freeze for no reason that I can see. The only thing I can figure is that maybe it has something to do with memory overflow.

Hopefully the program should work for you bug free on the first try, but, if not, let me know so I can try to fix it. You'll be the first to try this using both wormgears and the Adafruit shield.

Most everything you need should be at the top of the "Jim's Arduino Sun Tracker V9.9" tab. It all should be pretty well explained in the code's comments and in the earlier version of the program's documentation page on this site.

The one major difference from the old version is the way you program in the settings for each machine. It's a lot cleaner now, especially if you are trying to set up multiple machines. It is now set up using an array of arrays. Each line in the array contains the settings for one machine. If more machines are needed, just change the numberOfMachines variable and add the appropriate number of lines.

The code looks like this...

////////////////////////////////////////////////////////////
//START MACHINE SETTINGS
////////////////////////////////////////////////////////////    

 //Put how many machines you want to control here
 #define numberOfMachines 1

 const float MachineSettings[][17] PROGMEM = {
 //Setting #    0      1     2      3     4     5     6     7      8     9    10     11    12    13    14       15    16
                 {  0  ,   2 ,   50 ,  -1 ,   0  ,  0  ,  0  ,  0  ,  -1 ,   50 ,  1 ,   0 ,   0 ,    0 ,    0    ,    -60,   60 },
              //{  1  ,   2 ,   20 ,  -1 ,   20 ,  20 ,  90 ,  1   , -1 ,  20 ,   1  ,  16 ,  11 ,  90 ,  1   ,  -60 , 60 }
              
  };

You'll find comments below this code that specify which setting does what. I think you should be able to figure it out, but, if not, let me know.


Also, under the tab "TargetControl" and below several lines of commented out code that you aren't using, you'll find where you can program the altitude and azimuth for your target.

  MachineTargetAlt[0] = 0;
  MachineTargetAz[0]  = 0;


Let me know how it goes.

Thanks!
Gabriel

« Last Edit: May 20, 2011, 09:05:05 AM by Gabriel »


Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #31 on: May 20, 2011, 11:17:18 AM »
Thanks for replying back so quick.
I like the way the machine came out in general, but there is still plenty of room for improvement. Next one will have all the the electronics, including limit switches, mounted inside the square tube, which will need to be slightly longer. Should be really clean then! I will also add better shaft bushings and attempt to make the whole thing weather proof.
Thanks for all the work on the code. I'll be digging into it tonight, and hopefully have something to report by tomorrow.
Cheers!
Jim


Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #32 on: May 20, 2011, 07:02:30 PM »
It's alive!
I updated the code with my current location (Tucson, AZ, 32.132, 110.876) and fiddled with some of the machine setup stuff. Still need to do the alignment, but when I powered it up I was pleased to see it find the limit switches and then head off in the right general direction with both axes, then periodically update position west and down as you would expect this time of day. The sun is just going over the hill now, so I think I'll call it a night and celebrate the first baby steps with dinner and some of the local cerveza. Maybe do some studying later tonight if my brain is still working after that...
This is getting exciting!
Jim

Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #33 on: May 20, 2011, 09:30:22 PM »
Well the thing went and parked itself at 2100 local time. So far so good! I'm far to lazy to get up before dawn to see it come alive again, but maybe I'll tie some tin cans to it or something so it lets me know when it wakes up in the morning.
One thing I'll want to change eventually is to put in a Mosfet switch or something to shut off the power to the stepper driver between updates. The motors do waste some power (heat) but my heavy housing makes a good heat-sink and it gets just slightly warm after being on for a couple hours.
Gabriel I believe you mentioned that point as one of the advantages of your basic controller, that it doesn't energize the motors except during stepping. Anyhow, it should be simple to add a few lines of code to switch one of the digital outputs on whenever it needs to move somthing. I may take that on as one of my first forays into Arduino programming. Gotta start learning it eventually!
More tomorrow...

Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #34 on: May 21, 2011, 10:59:09 AM »
The machine woke up around sunrise and started doing it's thing.

Now I need to start getting things aligned.

Just to make sure I've got my reference angles right,  I am assuming the following with respect to the way the mirror is facing:

AZ zero ref = south, east is -, west is + ; EL zero ref = horizon, up is +, down is -). Am I looking at this correctly?

There is little binding problem in the EL gear which I need to resolve, but I'll be running it on the bench most of the day so I can make sure everything is behaving right before setting it up outside.

Jim


Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Mechanical Design
« Reply #35 on: May 21, 2011, 11:41:25 AM »
Sounds like its going really well! I'm glad that the Adafruit code is working like it should. It's always kind of nerve wracking uploading code that you haven't tested yourself.

It sounds like you have the right idea with the reference angles. There is a forum thread at this link which has some pictures that might be helpful.
http://cerebralmeltdown.com/forum/index.php?topic=289.0

It might just be a typo, but the lat and long you gave (Tucson, AZ, 32.132, 110.876) should have a negative longitude instead of a positive one like this,(Tucson, AZ, 32.132, -110.876).

If you wanted to try and use a MOSFET to turn the power on and off to the stepper motors, you could put the code for doing so inside the machineOn, and machineOff functions. I commented out all of it because it contains the code for the shift registers, but you could easily use it as a template for controlling the MOSFET.

Good Luck!
Gabriel

Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #36 on: May 21, 2011, 12:39:35 PM »
Yes it is going very well. I'm so excited I can hardly stand it.
You're right about the -110. That's what I entered in the program. Just typed it wrong here.
I just checked the sun position against  a NOAA online calculator. It is within about .2 deg in both AZ and EL. I noticed my Arduino clock is off by about a minute which probably accounts for the offset. So far everything seems to be working exactly as it should. I think I'll rig some kind of gun-sight instead of a mirror and run it in the straight sun tracking mode for a while and see how accurate it is before I throw in the additional complication of the heliostat mode.
Thanks for the tip on the "machine on/off" functions.
Cheers!
Jim


Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #37 on: May 22, 2011, 12:44:42 AM »
Just a quick report - the thing tracked through the day as far as I could measure with a digital protractor and compass in the shop. It nailed the sunset within a minute.
Tomorrow she's going outside with the "gunsight" setup. I made a little target where I can mark where the shadow falls throughout the day. From that and a little basic trig I should get a pretty good read on the overall tracking accuracy of the system.
Jim

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Mechanical Design
« Reply #38 on: May 22, 2011, 07:04:56 AM »
If you have been able to track the sun so well thus far, then the heliostat tracking should also work well. I've been meaning to thoroughly check the sun tracking in a real life set up, but it sounds like you did that for me.  8)

I would be interested in seeing how consistent the reflected light stays in one place with a system as rigid as yours.

Gabriel

Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #39 on: May 22, 2011, 02:21:23 PM »
Well the angles tracked pretty well yesterday, but it was indoors. Today is the first time it's been outside, and I didn't get started till almost noon. Had a little trouble sorting out the AZ alignment, but I think I have it fairly close now. For some reason the whole compass deviation thing is giving me fits. I understand the concept just fine, but always get myself confused over which way to apply the offset when going from "true" to "mag" and back. Then when I add in the different zero reference that the heliostat uses, and the +/- 90 thing, my brain gets tied in knots. Banging my head on the wall a few times usually helps untangle things.
I'll watch it till sundown and report back. Probably won't get to the heliostat part until next weekend as I still haven't started on the mirror mount.
Jim

Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #40 on: May 22, 2011, 07:50:57 PM »
Looks like I have some more tinkering to do. The tracking got progressively further behind throughout the afternoon, a couple degrees after about 3 hours, but re-homing it brought it back to where it should have been. I didn't notice it yesterday because I was fiddling with the code and it would re-home every time I re-uploaded some changes so it never got very far behind.
I suspect I'm losing some steps on each update cycle. My motors are pretty weak but the Adafruit driver is just about maxed out. There is an option to upgrade the driver with some stronger chips and I can also raise the supply voltage to give the motors a little more "kick".  I'll order the chips tomorrow. Meanwhile I'll play around with slowing down the step speed (currently at 25) to see if that helps at all, but homing is painfully slow already so that's not a great option. Getting that accel/decel driver working might help, but for now I'll pursue the "brute force" approach.
Overall I'd consider this first test run a great success, as it has demonstrated that the software works, at least in the sun tracking mode, and has clearly shown where improvement is needed in the machine.
Jim

Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #41 on: May 23, 2011, 06:29:06 PM »
Well I decided to try and confirm the cause of the position lag with more certainty before beefing up the driver. To that end I wrote a little program that moves one axis in many short increments in one direction, then returns to the start point in one continuous movement. I was thinking that if it was losing steps due to insufficient torque, it would most likely happen at the beginning of each movement, so with multiple small movements you would see an accumulating error. So far there is no apparent error after several dozen cycles.
So... now I'm wondering if it is an accumulation of round-off errors in the code. I read somewhere on this site that there was a round-off error whenever a fractional number of steps was called for. Seems to me that it would be more or less of a problem depending on things like gear ratio and such.
Maybe something else is going on, but that was just a thought.
Any ideas?

Jim McMillan

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Mechanical Design
« Reply #42 on: May 23, 2011, 08:53:58 PM »
Some more info...
I was able to make it lose occasional steps by increasing the motor rpm to 40, but it's solid at 25 where I was at yesterday.
Some careful studying of my record from yesterday (I was marking shadow position hourly on my test target) shows about 2 degrees of AZ offset over 3 hours, and a little under 1 on the EL. This was measured by noting shadow positions after a 3 hour run before and after re-homing and then measuring the horizontal and vertical distance between the marks, then doing some trig based on the length of the shadow rod to get the offset angles. It comes out to a loss of about 26 steps per hour in elevation, and about 13 in azimuth. The machine is set to update every 3 minutes, so that's 1.33 and .66 steps per update cycle. Admittedly these are very rough measurements, but maybe there's a clue in there somewhere. If it were caused by the suspected round-off error, I think it would average about 1/2 step per update cycle. There's enough uncertainty in my measurements that it could easily be in that range. Or not... I'm mostly speculating. Will try and get some better measurements.
Jim

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Mechanical Design
« Reply #43 on: May 24, 2011, 05:12:24 AM »
When I updated the program, I tried compensating for the round off error by saving the lost steps and then adding them back in during the next cycle. I'll have to double check it this afternoon to make sure I didn't leave something out by accident.

If might help if you could upload your sketch with your settings so that we are both looking at the same thing.

Thanks,
Gabriel

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 651
    • View Profile
Re: Mechanical Design
« Reply #44 on: May 24, 2011, 09:29:59 AM »
Hey Jim,

I took a close look at the code, and there is indeed a bug with how it compensates for lost steps. I sort of have it fixed I think, but I am still trying to figure out why I'm getting different answers depending on whether I simulate the program to calculate the total number of steps taken after a reset versus the total number of steps during an all day simulation.

Once I get it all worked out I'll upload the fixed version.

Thanks for catching the bug,
Gabriel