| View previous topic :: View next topic |
| Author |
Message |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Tue Jul 13, 2010 11:13 am Post subject: V3 Experimental Branch |
|
|
Hi All (specifically KBB)
I decided to make a new thread for your OpenServo_V3-experimental branch. For the sake of keeping everyone else up to date, I have 8 OpenServo's (MG995's and MG996's) with OpenEncoders installed. I wanted to find a better way to control them as the stock firmware in the CVS repository doesn't have any I control (Just P+D). While attempting to create a new PID module, KBB came to me and said that he had created a new PID module and he had put in into the CVS in the AVR_OpenServo_V3-experimental folder. However, he did not have OpenEncoders, and therefore could not test the compatability with my servos. Eager to avoid having to rewrite my own module, I started testing his code with my servos. I created this thread for discussion about the development of the "experimental" branch in hopes that we can bring better PID control to OpenServo. |
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Tue Jul 13, 2010 11:21 am Post subject: |
|
|
i just spent a couple days testing the software on my servos and when I first installed it, the P and I worked, but I had no luck getting the D to work. Now, it appears that all three of them are working after some small modifications I made. I'm not sure how to access the CVS to commit them but I would be happy to send them to you if you want (just in the pid.c file)
This branch does work with OpenEncoder and I have had success tuning the PID settings.
My only complaint is that the PID control is not quite good enough with the higher resolution of the OpenEncoder. The motor will consistently get within 5 positions of the desired position and then stop while the code keeps running trying to get the motor to reach the seek position. Ideally, there would be a way to get the motor to reach that one position everytime.
Other than that, the PID module is working well. Thank you KBB!
EDIT: Also, when I have the servo move for a distance longer than 180 degrees, the motions is very inconsistent and seems to move in long pulses. Seem familiar? |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Tue Jul 13, 2010 9:37 pm Post subject: |
|
|
| wpotter wrote: | | i just spent a couple days testing the software on my servos and when I first installed it, the P and I worked, but I had no luck getting the D to work. Now, it appears that all three of them are working after some small modifications I made. I'm not sure how to access the CVS to commit them but I would be happy to send them to you if you want (just in the pid.c file) |
Do you mean the one I put in “experimental” about 2 days ago or the one that was there prior to that? Anyway, maybe you can send the pid.c to me and I’ll see how things fit? There are certainly some improvements to be made. You should be able to tune P, I and D with the one that is there...
However, I have now been thinking about the full rotation implementation: and there appears to be at least one obvious issue. It is possible that this implementation may be the cause of your problems. Hopefully I will soon (probably a few weeks rather than days) be in a position to test with an OpenEncoder.
The first issue I have spotted would appear to be direction: with the standard servo there is no choice. But with full rotation there is, but there is nothing in the software to handle it. And another example, what is supposed to happen if you say “move to 4000” when it is at “100”.
Potentially these issues could be handled by allowing negative as well as positive seek velocities to indicate direction. This didn’t occur to me as I was working on standard servos, so the code may not work well as it stands if you have been trying that.
I will see if I can work this out before I am able to test it.
| wpotter wrote: | This branch does work with OpenEncoder and I have had success tuning the PID settings.
My only complaint is that the PID control is not quite good enough with the higher resolution of the OpenEncoder. The motor will consistently get within 5 positions of the desired position and then stop while the code keeps running trying to get the motor to reach the seek position. |
Why do you think it is the resolution (unless it is causing an overflow or something)?
Whilst it is not perfect, it might still possible you need a bit more tuning. Or, double check what the dead-band is set to… maybe it is 5?
What are the parameters you are using? Try a "defaults" to ensure it is "clean".
| wpotter wrote: | | Ideally, there would be a way to get the motor to reach that one position everytime. |
With no load I would expect it to do that now (except for any issues with the full rotation implementation). Do you have a load on it?
| wpotter wrote: | Other than that, the PID module is working well. Thank you KBB!
EDIT: Also, when I have the servo move for a distance longer than 180 degrees, the motions is very inconsistent and seems to move in long pulses. Seem familiar? |
Possible a problem with the lack of direction in the full rotation implementation? You might test that by building a firmware with full rotation disabled, and then see how it behaves in the mid-section of the range of travel (i.e. you don’t want it near 0 or 4095 because it will likely be unstable).
EDIT: Previously it said "continuous rotation" when it should have said "full rotation".
Last edited by kbb on Wed Jul 14, 2010 7:16 am; edited 1 time in total |
|
| Back to top |
|
 |
jharvey co-admin
Joined: 15 Mar 2009 Posts: 350 Location: Maine USA
|
Posted: Wed Jul 14, 2010 12:08 am Post subject: |
|
|
The 5 ticks is likely the band gap thing. I seem to recall that OE can detect nearly 5 ticks based on gear backlash alone. The band gap is programmable via I2C. However, that band gap will have to correlate to the same band gap in the python script. So be careful, keeping those in sync.
A while back I posted a video showing an OE servo moving. When seeking a position at high RPM, and at about every 1/4 rotation, you can hear a change in the motor sound. I'm not exactly sure what is causing that, but I suspect it's the processor trying to keep up with the position. For position changes at under 1/4 rotation, it seems to get there with out those little skipps. I would expect normal operations will not need to run at the full RPM of the motor, and will actually want to rotate much slower. I would expect that jitter would cause the end position to vary from the commanded position. For example, if you command it to move 90 degrees from it's current position, it starts with 90 degrees of jitter. I would suspect that you would want less jitter, and would instead command it to move 10 degrees 9 times. I suspect that a normal application will be sending a continuous thread of positions, and the servo will try to hold those commanded positions as best it can. However for rapid moves this would be handy to iron out.
The direction thing, I seem to recall that the OE firmware figures out how to get there on it's own as well it's done via I2C commands. It's required for when it crosses the 0 degree transition. Perhaps that's done with another function and perhaps this other potential function is the source of the skips. I seem to recall that you've only got 1 rotation of buffer, then you had to keep track of larger numbers on the other side of the I2C. For example, you can't command OE to move to 645 billion, it's simply to big for OE. Instead it's limited to a max, and by using the direction thing, you can rotate it beyond it's max, and keep track of those bits at the commanding device. |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Mon Jul 19, 2010 9:36 pm Post subject: |
|
|
Looking at the code as it stands; whilst full rotation direction could be controlled by sending regular position changes to reach a destination, note that with position changes approaching 180 degrees or greater you cannot tell it to go there directly. This would be because the servo will move in the direction of the shortest path between the current and desired position, which may be in the opposite direction to what you want.
Ideally I would have thought that telling it which direction would be the best option. We could set this up as a configurable build option (for example #define FULL_ROTATION for direction control and #define FULL_ROTATION_CLASSIC for what is currently done).
Also “missing” from the full rotation implementation is a “continuous rotation” function; again this could be added as a configurable build option.
Note that controlling the position externally to achieve direction and/or velocity control might result in some jerky movement- as the servo firmware is already trying to do that itself. But there are other causes as well... From my observations with my other experimental firmware, I suspect the PID/PWM implementation needs a bit of a review when used with higher power servos. Things to look into later... |
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Thu Jul 22, 2010 7:50 am Post subject: |
|
|
Sorry for my long delay, I have been away from the office for the past week.
| kbb wrote: |
Do you mean the one I put in “experimental” about 2 days ago or the one that was there prior to that? Anyway, maybe you can send the pid.c to me and I’ll see how things fit? There are certainly some improvements to be made. You should be able to tune P, I and D with the one that is there...
|
I have many different versions of the pid.c file floating around, and actually I think I am using your original one right now. I will send it for you to take a look at anyways in a private message.
| kbb wrote: |
However, I have now been thinking about the full rotation implementation: and there appears to be at least one obvious issue. It is possible that this implementation may be the cause of your problems. Hopefully I will soon (probably a few weeks rather than days) be in a position to test with an OpenEncoder.
The first issue I have spotted would appear to be direction: with the standard servo there is no choice. But with full rotation there is, but there is nothing in the software to handle it. And another example, what is supposed to happen if you say “move to 4000” when it is at “100”.
Potentially these issues could be handled by allowing negative as well as positive seek velocities to indicate direction. This didn’t occur to me as I was working on standard servos, so the code may not work well as it stands if you have been trying that.
|
The motor goes the long way to 100, rather than crossing 0. So that needs to be handled definitely. I will trying allowing negative seek values to cover direction.
| kbb wrote: |
Why do you think it is the resolution (unless it is causing an overflow or something)?
Whilst it is not perfect, it might still possible you need a bit more tuning. Or, double check what the dead-band is set to… maybe it is 5?
What are the parameters you are using? Try a "defaults" to ensure it is "clean".
| wpotter wrote: | | Ideally, there would be a way to get the motor to reach that one position everytime. |
With no load I would expect it to do that now (except for any issues with the full rotation implementation). Do you have a load on it?
|
We have not tried it with a load, but it was tuning. Right now it works pretty well, but we will have to retune anyways when we install the servos into the arm so I will not invest too much time tuning an empty servo.
| kbb wrote: |
Possible a problem with the lack of direction in the full rotation implementation? You might test that by building a firmware with full rotation disabled, and then see how it behaves in the mid-section of the range of travel (i.e. you don’t want it near 0 or 4095 because it will likely be unstable).
EDIT: Previously it said "continuous rotation" when it should have said "full rotation". |
It sounds like I need try and configure the directions and positions of the motor. I will try that and post back on my findings. If there is anything that you need checked with encoder motors until you get yours, please don't hesitate to ask. |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Sun Jul 25, 2010 9:50 am Post subject: |
|
|
| wpotter wrote: | | I have many different versions of the pid.c file floating around, and actually I think I am using your original one right now. I will send it for you to take a look at anyways in a private message. |
The one you have sent doesn't look like the original. I will compare them, see if it offers any improvments.
The firmware in AVR_OpenServo_V3-experimental is not my original experimental firmware: it is the AVR_OpenServo_V3 “branch” with a few key features from the experimental firmware added in. The original experimental firmware is based on the AVR_OpenServo_V3-dev “branch” which does not contain OpenEncoder support, and also has many other subtle differences.
I'll be uploading a new AVR_OpenServo_V3-experimental soon.
I don’t know why OpenEncoder was added to AVR_OpenServo_V3 rather than AVR_OpenServo_V3-dev.
At some point we need to review the whole PID/PWM implementation (I have probably mentioned that before). Maybe once the V4 is off the launch pad? |
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Mon Jul 26, 2010 6:52 am Post subject: |
|
|
| jharvey wrote: |
The band gap is programmable via I2C. However, that band gap will have to correlate to the same band gap in the python script. So be careful, keeping those in sync.
|
I will try that and let you all know how it goes, but for now we will focusing more on the direction/movement consistency stuff. If all goes wrong with the band gap stuff, we can always just implement a buffer in the python script because it appears that the OE gives very very accurate positions.
| jharvey wrote: |
A while back I posted a video showing an OE servo moving.
|
Is it in the wiki?
| jharvey wrote: |
However for rapid moves this would be handy to iron out.
|
This is where we feel we will be placing the most emphasis as we will mostly have short, rapid movements, most of which less than 180 degrees. I hope to install the servos in the arm soon and begin experimenting.
| kbb wrote: |
Looking at the code as it stands; whilst full rotation direction could be controlled by sending regular position changes to reach a destination, note that with position changes approaching 180 degrees or greater you cannot tell it to go there directly. This would be because the servo will move in the direction of the shortest path between the current and desired position, which may be in the opposite direction to what you want.
Ideally I would have thought that telling it which direction would be the best option. We could set this up as a configurable build option (for example #define FULL_ROTATION for direction control and #define FULL_ROTATION_CLASSIC for what is currently done).
|
I like that idea, I will start trying to do that and I will let you know how it goes.
| kbb wrote: |
At some point we need to review the whole PID/PWM implementation (I have probably mentioned that before). Maybe once the V4 is off the launch pad?
|
I agree completely that we should review the PID. Unfortunately, I will be finishing my internship at my current company in 3 weeks. I have to try and get these motors as well prepared as possible before I leave and I don't know if I will be here by the time V4 takes off. We will see how it plays out though. |
|
| Back to top |
|
 |
jharvey co-admin
Joined: 15 Mar 2009 Posts: 350 Location: Maine USA
|
|
| Back to top |
|
 |
wpotter
Joined: 18 Jun 2010 Posts: 50 Location: Valencia, Spain
|
Posted: Tue Jul 27, 2010 7:01 am Post subject: |
|
|
I am in the process of putting integral windup control into my new firmware. That might contribute to my large error when the servo moves large differences.
EDIT: It is already there, I just missed it.
Last edited by wpotter on Wed Jul 28, 2010 7:34 am; edited 1 time in total |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Tue Jul 27, 2010 4:16 pm Post subject: |
|
|
| I now have an OpenEncoder up and running. There clearly appears to be something “not quite right” about the firmware’s behaviour when it is built with the encoder support. I will investigate shortly. |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Fri Jul 30, 2010 10:24 pm Post subject: |
|
|
Okay: I have uploaded an improved firmware to the “V3-experimental” branch of the OpenServo CVS. I have not included precompiled .hex files (although I could make a number of the popular combos).
Let me know if there are any anomalies.
Here are some notes:
Reminder: this firmware is derived from the “AVR_OpenServo_V3” firmware (because that is where the OpenEncoder support was added). Therefore the new features from “AVR_OpenServo_V3-dev” are missing. On the other hand that means that it is probably better for those of you already using an OpenEncoder build. If I get time I will make an updated version of “AVR_OpenServo_V3-dev” and we’ll see where to put it.
Reminder: when compiling, remember to update config.h to match your setup!
I would recommend executing “defaults” and “save” the first time this firmware is uploaded to the servo. Or at least checking the gains and dead-band setting.
If minimum and maximum positions are programmed in, then they will be adhered to. So for full-rotation you will need to reset them: “defaults” will set them to [0,4095] when full rotation is enabled.
I have added a new hardware type of HARDWARE_TYPE_MG995 to config.h with some conservative settings.
It will not drive the motor unless the velocity is >zero (and PWM is on). For example: try writing 4 to 0x13 to set a velocity (0 to 0x12 if it isn’t already) - No, I don’t know why the registers have been implemented big endian!
There are a lot of things I have not had time to address. These include:
Allowing the full rotation direction to be specified by using negative and positive velocities.
Over-shoot.
Determining the best way to handle the potential build up of the integral term. Actually there is lots of potential for improvement; this may have to wait for V4- a code reworking would be useful and if done correctly will be compatible with both V3 and V4. |
|
| Back to top |
|
 |
jharvey co-admin
Joined: 15 Mar 2009 Posts: 350 Location: Maine USA
|
Posted: Fri Jul 30, 2010 11:19 pm Post subject: |
|
|
Cool, I'll have to give it a try some time. I've just shifted my projects around, so I should be able to find more time for this. Any chance you can compile and post a hex file for a MG995 with OE?
I'm curious does this use the same registers and commands as the other OE firmware? |
|
| Back to top |
|
 |
kbb
Joined: 01 Jun 2007 Posts: 180
|
Posted: Sat Jul 31, 2010 12:04 am Post subject: |
|
|
| jharvey wrote: | | Cool, I'll have to give it a try some time. I've just shifted my projects around, so I should be able to find more time for this. Any chance you can compile and post a hex file for a MG995 with OE? |
I have uploaded 4 pre-compiled firmwares featuring the (hopefully) conservative parameters found for the MG995 in config.h:
ATmega168_OpenServo_V3-oefr.hex
ATmega168_OpenServo_V3-oefr_twichk.hex
ATmega168_OpenServo_V3-pot.hex
ATmega168_OpenServo_V3-pot_twichk.hex “pot” indicates a potentiometer using build
“oe” indicates an OpenEncoder using build
“fr” indicates full rotation is enabled
“twichk” indicates the checksumed version of TWI/I2C is enabled
All other options are as currently found in the config.h.
| jharvey wrote: | | I'm curious does this use the same registers and commands as the other OE firmware? |
It uses the same registers and commands as the code found in AVR_OpenServo_V3. |
|
| Back to top |
|
 |
jharvey co-admin
Joined: 15 Mar 2009 Posts: 350 Location: Maine USA
|
Posted: Sun Aug 01, 2010 1:20 pm Post subject: |
|
|
Awesome and thanks for posting the pre-compiled firmwares. I've run some quick tests and they appear to be a near feature match of my original firmware. However, my move script isn't working. Here's what I'm discovering in my short look at it.
my scan script reports nearly the same thing as my original script. | Code: | $ ./os-scan.py
found device at address 0x10
stat = 00 10 18 00 02 00 00 00 50 58
regs =
0x00: 01 01 00 02 00 03 89 5e 00 02 00 00 00 05 00 00
0x10: 05 58 80 00 02 e0 00 07 00 00 00 00 00 00 00 00
0x20: 10 01 06 00 00 00 00 00 00 40 00 00 0f ff 00 26
0x30: 02 00 3f 21 26 26 00 00 00 00 00 00 00 00 00 00
0x40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x60: 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26
0x70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
$ flashed to org
-bash: flashed: command not found
$ ./os-scan.py
found device at address 0x10
stat = 00 10 18 00 80 00 00 00 50 50
regs =
0x00: 01 01 00 02 00 03 07 d9 00 02 00 00 00 05 00 00
0x10: 00 02 00 00 02 e1 00 00 00 00 00 00 00 00 00 00
0x20: 10 00 00 00 00 00 00 00 00 40 00 60 03 a0 00 24
0x30: 03 00 3f 21 00 00 00 00 00 00 00 00 00 00 00 00
0x40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x60: 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24
0x70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
| my get position script reports the same range of values as the original firmware. It also confirms I can disable PWM.
My move script that normally bounces between several multi turn positions, will simply sit there seeking the first position. Here's the basic flow of that script. setpgain(600), setigain(0), setdgain(0), writedisable, enablePWM, setvelocity(0x8000), setseekrange(0, 0xfff), moveto(180)
The motor PWM does enable and locks the shaft, such that I can't turn it with the little lever I have attached to the shaft. However, it's not at 180 degree, so the script doesn't move on. Also it doesn't move so it's not actually seeking the position. My guess is that the seek range and set velocity are good. When I get a chance, I'll look a bit closer at how it sets the seek position. My guess right now is that the script is sending a new position in a different manner than the new firmware expects. |
|
| 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
|