| View previous topic :: View next topic |
| Author |
Message |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Tue Jul 06, 2010 11:48 am Post subject: |
|
|
| My original code compiled fine , but when I applied the patch, I just saw compiler errors. Do you make your .hex files with AVR Studio or command line gcc? |
|
| Back to top |
|
 |
jharvey co-admin
Joined: 15 Mar 2009 Posts: 350 Location: Maine USA
|
Posted: Wed Jul 07, 2010 12:19 am Post subject: |
|
|
I'm not familiar with AVR studio, I believe it's GCC. According to the make file
CC = avr-gcc
So it should be avr-gcc, not normal gcc. |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Wed Jul 07, 2010 8:16 am Post subject: |
|
|
I have an “experimental” V3 firmware (I just uploaded it to CVS as AVR_OpenServo_V3-experimental). It has a substantially different pid.c and various other minor changes to things to accommodate that (mainly adc.c and pwm.c; but probably main.c too); but I did my best to leave things alone outside of it. It implements velocity control in a different way too. Some aspects of it I don’t like. Ginge also tells me it has broken the “motion control” part of the firmware- if you are not using “motion control” you might like to give it a go.
A couple of points:
You need to set a velocity (for example: 0x0020), you can turn velocity control off by setting it to 0x8000 (the servo will move as fast as it can within the bounds of power available, mechanical issues, PID setting and so on). If it is set to 0, the servo will not move.
With all firmware versions:
Ever increasing P, I and D gain values are not “good” - tune them or try the defaults.
There are many factors affecting the maximum speed the servo will move at; some of those are nothing to do with the software.
I don’t think the velocity control in the other firmware works properly.
It is always a good idea to turn “PWM” off before changing the P, I or D gain values.
Using the command to set the defaults also sets the address back to 0x10?
A number of things can prevent the servo reaching or appearing to reach the set position; including the load is too great for it to happen or the dead-band settings mean that power is off near the set position. I am a bit swamped, but if I have any thoughts about this I will update this post.
If you want a servo to start with the various parameters you have set; remember to save them!
After installing a “completely different” firmware it may be wise to set the servo defaults, correct the address, save and then reboot it? |
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Wed Jul 07, 2010 9:20 am Post subject: |
|
|
| Unfortunately the patch did to work. The firmware compilled and uploaded fine however the motor still rotated around infinitely when I put in a position. Odds are its something with my PID algorhytm...hmm. This is a grope, unfortunately, we really need the precision so I will keep plugging away. |
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Wed Jul 07, 2010 9:22 am Post subject: |
|
|
| I will try that KBB...Sorry I had not refreshed the post and thus did not see that you posted. Thank you! |
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Wed Jul 07, 2010 10:04 am Post subject: |
|
|
KBB:
I just compiled your firmware and uploaded it. When I ran my script, the PID values set, and then when I inputted a position, the motor began to continuously spin on and on. I set it to give continous position feedback while it would continously rotate and the position read the same number while the motor rotated around and around.
Have you seen that happen? |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Wed Jul 07, 2010 9:11 pm Post subject: |
|
|
| wpotter wrote: | KBB:
I just compiled your firmware and uploaded it. When I ran my script, the PID values set, and then when I inputted a position, the motor began to continuously spin on and on. I set it to give continous position feedback while it would continously rotate and the position read the same number while the motor rotated around and around. |
Are you using OpenEncoder with a servo modified for continuous rotation, rather than a standard pot configuration? Otherwise "continuously spin on and on" is bad news (broken servo hardware).
I am sorry, the OpenEncoder support is not in that experimental firmware as it was built from the "dev" tree. OE support would need to be ported across to it.
I don't have OpenEncoder hardware so I would not be able to test it; but if you confirm that it is OE you need I will see if I can patch it in for you to try. |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Wed Jul 07, 2010 10:13 pm Post subject: |
|
|
I am not using "FULL_ROTATION_ENABLED", but the code that appears in OpenServo\AVR_OpenServo_V3\pid.c (which seems to be the only code using this) may have a bug. As it stands it reads:
| Code: | // Keep the seek position bound within the minimum and maximum position.
if (seek_position < minimum_position) seek_position = minimum_position;
if (seek_position > maximum_position) seek_position = maximum_position;
// The proportional component to the PID is the position error.
#if FULL_ROTATION_ENABLED
p_component = normalize_position_difference(seek_position - current_position);
#else
p_component = seek_position - current_position;
#endif |
which I think should probably read
| Code: | #if !FULL_ROTATION_ENABLED
// Keep the seek position bound within the minimum and maximum position.
if (seek_position < minimum_position) seek_position = minimum_position;
if (seek_position > maximum_position) seek_position = maximum_position;
// The proportional component to the PID is the position error.
p_component = seek_position - current_position;
#else
p_component = normalize_position_difference(seek_position - current_position);
#endif |
Last edited by kbb on Thu Jul 08, 2010 9:40 pm; edited 1 time in total |
|
| Back to top |
|
 |
jharvey co-admin
Joined: 15 Mar 2009 Posts: 350 Location: Maine USA
|
Posted: Thu Jul 08, 2010 12:23 am Post subject: |
|
|
| Yes he has OE servos. |
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Thu Jul 08, 2010 10:45 am Post subject: |
|
|
| I will try and adapt your PID algorithm for Open Encoder. For now, I will just try and struggle by with P+D. Is there an optimal velocity value? |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Thu Jul 08, 2010 10:04 pm Post subject: |
|
|
| wpotter wrote: | | I will try and adapt your PID algorithm for Open Encoder. |
I am about 60% of the way thru moving the encoder code into the experimental firmware. Although the last 20% will probably the trickiest to get close to being right since I cannot currently test it. On the plus side of doing this, I think I have spotted why "motion control" is broken in this version.
| wpotter wrote: | | For now, I will just try and struggle by with P+D. Is there an optimal velocity value? |
When I was using the original firmware I did not get any sensible behaviour from the velocity setting.
In the experimental firmware the method for velocity control is different; the value you are setting is the real velocity you want to try for in terms of 1/16th pot/encoder value per cycle (by default). So there isn’t really an optimal value with that method. As I see it, for most purposes velocity control is not a tuning parameter; it is to satisfy a requirement to move at a particular speed. For example: we want to lift the biped's foot up rather than snatch it off the floor as fast as possible.
There will be the maximum speed the servo can physically achieve given the gearing and available power.
There will be "load effects". For example: whilst the code may achieve a desired velocity, if the load suddenly changes it will either, depending on how the load was altered, slow down or speed up and so on. |
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Fri Jul 09, 2010 5:42 am Post subject: |
|
|
KBB:
| Quote: | | When I was using the original firmware I did not get any sensible behaviour from the velocity setting. |
Neither did I. The only value that behaved as expected in the original OpenServo_V3 firmware was the P for me. There was no way of telling when I changed the D, I or Velocity values. The motor movement only reflected the change in P value. As such, I deemed it necessary to try and write my own PID module. Unfortunately, I have had no luck and am clinging to any advice I can pull from the forums. |
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Fri Jul 09, 2010 6:19 am Post subject: |
|
|
This is not good. So I put an experimental version of my software (Self titled V1) on three servo (The loop above the I gave, but slightly modified). When I tested the software, I was able to put the gain in and then I inputed a position to move to. When I put the position in and hit enter, the motor would continue to spin on and on forever. The continuous position feedback I have just outputted 1023 (normally a legitimate position). So, I pulled the power out and then updated the CVS. Made a copy of the OpenServo_V3 firmware. However, when I uploaded the new firmware on, the same error happened and it just spun round and round as if nothing changed.
I am assuming that the problem is that the Open Encoder is set to off in the config.h file?
Otherwise, it has to be hardware.
If I want to make a "stock" version with OE support, do I just have to set it on?
EDIT: I just compiled a new version of the stock firmware with the OE flags and the full rotation flags enabled...success (still no i or d as far as I can tell, but P works again.) When I set D as well, the motor continously rotates, however, now it give accurate feedback while doing so. P-only works but when I add any D value, the motor continously rotates. The velocity is set at 0x8000. |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Sat Jul 10, 2010 12:58 pm Post subject: |
|
|
| wpotter wrote: | This is not good. So I put an experimental version of my software (Self titled V1) on three servo (The loop above the I gave, but slightly modified). When I tested the software, I was able to put the gain in and then I inputed a position to move to. When I put the position in and hit enter, the motor would continue to spin on and on forever. The continuous position feedback I have just outputted 1023 (normally a legitimate position). So, I pulled the power out and then updated the CVS. Made a copy of the OpenServo_V3 firmware. However, when I uploaded the new firmware on, the same error happened and it just spun round and round as if nothing changed.
I am assuming that the problem is that the Open Encoder is set to off in the config.h file?
Otherwise, it has to be hardware.
If I want to make a "stock" version with OE support, do I just have to set it on?
EDIT: I just compiled a new version of the stock firmware with the OE flags and the full rotation flags enabled...success (still no i or d as far as I can tell, but P works again.) When I set D as well, the motor continously rotates, however, now it give accurate feedback while doing so. P-only works but when I add any D value, the motor continously rotates. The velocity is set at 0x8000. |
As you have spotted, if you download a new copy of a firmware you have to remember to change the config to match your setup!
I am reasonably sure that for full rotation the code needs to be modified as shown a few posts above.
As for the continuous rotation when you set a D gain, I suspect one reason is as follows:
The PID control in the default and “-dev” firmware code appears to be “flawed” when there is a D-gain set. This is because it says:
| Code: | d_component = seek_velocity - current_velocity;
:
pwm_output += (int32_t) d_component * (int32_t) d_gain; |
So, if the calculated velocity does not match the seek velocity and d_gain is not zero, the motor will be driven; and there is no limiter in the code as far as I can see. It will almost always be true that the calculated velocity does not match the seek velocity; therefore a non-zero D gain may cause the motor to be driven unless PWM is turned off. If the gain is too large or the velocity is set too high, then the motor may well run continuously.
I flashed the base firmware into a test servo and tried it out. It is a bit unstable if we set a D gain, although I did not get “continuous movement” - only unwanted effects. I wonder if the continuous rotation is a result of the use of “normalize_position_difference”.
Anyway: a long story in short; I have been here before. Rather than try to explain it all, I will modify the code to implement a “standard” PID algorithm and add some velocity control to it.
I will let you know when I have done that.
Last edited by kbb on Sun Jul 11, 2010 10:43 pm; edited 1 time in total |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Sun Jul 11, 2010 10:42 pm Post subject: |
|
|
| wpotter wrote: | | EDIT: I just compiled a new version of the stock firmware with the OE flags and the full rotation flags enabled...success (still no i or d as far as I can tell, but P works again.) When I set D as well, the motor continously rotates, however, now it give accurate feedback while doing so. P-only works but when I add any D value, the motor continously rotates. The velocity is set at 0x8000. |
Okay it (see my other reply above) is done. There is now a copy of the OpenServo/AVR_OpenServo_V3 code in AVR_OpenServo_V3-experimental with a revised pid.c. Here are a few key points:
Remember to modify config.h to match your setup/usage!
You will probably need to tune your PID gain parameters again. Start with some simple values. Large values are unlikely to be good.
This firmware requires a velocity to be set (the default is 0, and of course 0 means it does not move). I would recommend using 4 until you have seen it go. Don’t use very large values (there is no point and it may upset the maths).
I haven’t tested it with encoder positioning.
I haven’t tested it with full rotation enabled: if you still get a “continuous rotation problem”, try turning full rotation off and see if that makes a difference and report back.
If I have time I will try to further improve the new pid.c; although it is likely I will be concentrating on the V4 design instead! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|