Dancebot not staying vertically
Karpovskaia
Posts: 22
I have had some major progress with my dance bot. I am currently using the modified code of Hanno's dance bot by Duane. But I have an adjustment problem. When I first load the program the velT, tilt, and the turn move back and fourth and takes about 10 seconds before they center in the fuzzy tab in viewport. Once they do center and the robot is tilted slightly there is a small delay for the velT, tilt, and the turn to catch up with the robot as it tilts. Its like the accelerometer needs to speed up or the code needs to read the sensers faster. My newbe experience tells me that the waitcnt (nCnt+=clkfreq/200) ' update tilt every 5ms. Needs to be be adjusted, but it did not work. I also tried other things in the tilt code, but no luck. If there are any suggestions. That would be awesome.
Comments
As I mentioned, I haven't made a balancing bot myself but I can think of several reasons why your bot could be having a hard time balancing.
My first suspicion is the control algorithm may not have a large enough proportional response to the sensor data. I think this would be part of "tuning" the various parameters of the robot's control algorithm.
My second suspicion is the motors aren't powerful or fast enough for the robot you've built.
Could you describe your setup? What motors are you using (preferably with a link)? What h-bridge circuit? What sensors are you using?
What kind of power supply? What kind and size of batteries?
It would also help if you attach an archive of your project so we could look at the code.
In order to archive your project, you need to first compile it. Then from the "File" menu select "Archive 'NameOfProject'" \ "Project...". This will create a zip file of all the files used in your project. You can attach the zip file by clicking the "Go Advanced" button (it on the bottom right of the text editor box when replying to a thread) and using the "Manage Attachment" feature (another button below the "advanced" text editor) to upload the file.
It would also be great if you could take a picture of your robot and attach it to your post.
For those who may be interested, crazyrobotgirl worked on a balancing bot here and here. I think Karpovskaia is using code from these threads.
and Im trying to do the rest on my own. The whole PID thing is very complicated.
let me know.
I don't have the DanceBot code handy. If you post your archive, I can make sure I'm looking at the same code you're using.
I don't recall if Hanno used a full PID algorithm or not.
The following always got me out of trouble.
Turn off all "I" and "D" gains run with proportional only.
Start with a low "P" gain and increase just until you get overshoot and the device, temperature, flow...whatever starts to oscillate around the desired set point. At this point back off the "P" gain until the oscillation stops. [NOTE: you will most likely NEVER be at the set point but close. This was usually the optimal setting for "P".
I would then enable the I gain and adjust till, once again, oscillation starts then back it off.
At this point, depending on the system, I usually did not need any differential (D) gain but if I did, I followed the same routine but this time making sure the system was neither too slow or fast to respond.
If you only work in one field you can evaluate the system and determine good starting points but in reality you may not know every variable so the method above will generate a tight PID loop control.
I hope I did this right.
I looks like you did attached the code correctly but the attached code is just the object for monitoring the gyro and accelerometer. I would like to see all the code. An archive of the top object will include all the objects used in the project. I explained how to archive your project in post #2.
With an archive, I can be sure I have the same version of child objects as used in your project.
It's usually better to post large amounts of code as an attachment. Small sections of code can be inserted in a post by using code tags. Phil wrote a tutorial of how to use code tags. (He also made the picture used to link to the tutorial.)
This one is the child object.
Load the top object in the Prop Tool and press F9 to compile it. Once the top object has been compiled you can create an archive.
The "Archive 'NameOfProject'" option will not actually have "NameOfProject" listed. The name of the top object of your project should be listed after "Archive".
I'm not positive which object the control algorithm is in. It's likely in one of the sections of code you posted but I would prefer to have a complete archive of the project before I look for it.
If I were to explain PID to a person with NO knowledge of computers or control logic it would be, [and forgive me if I over simplify and this is GREATLY oversimplified] the following;
Proportional [P]: How far away from the ideal set point is my system? The further away, the more gain I would need to get to the set point. (Set Point - Actual) * P-gain
Integral : How long have I been away from the set point? If I am always away too long, increase the rate at which I add/subtract I-gain. Add I-gain every Y seconds. ( i have worked on systems where you can only set the amount of I-gain and the timed interval is fixed, or you can set both the I value and adjust the time between when I-gain is added or subtracted.) Either one works but being able to control both is more powerful IMO.
Derivative [D]: Is the combination of P & I moving the system too fast?
EG: Automobile cruise control: The desired speed (set Point) vs the Actual speed become my Error! So if I have a low P gain that [error * P] might never even bring me close to the right speed. If I have a lot of P gain I might over speed, then slow down, over speed, slow down....
Now lets say I add some gain every second I am under speed (or subtract ever second if I am going too fast), now P + I will get me closer to the set point faster but just as before if I add too much gain I will over shoot and the car will start to hunt for the right speed.
Now if I have set both [P] & as high as possible without overshooting my set point, I may or may not have to add [D] and usually I did not. There are some exceptions. In some applications you may be so far away from your target that your system will cause damage trying to reach the set point. IE: Car set point 60 MPH and actual speed 0. With a well tuned P & I we might lay down a long strip of burned rubber attempting to get to 60 MPH as fast as possible. [this is why cruise controls drop out usually below 30 MPH]. The [D] gain in applications like this will slow down the system response so you don't over stress individual components.
Wurlitzer- nice description of PID! There's certainly a lot of art/experimentation to tuning PID constants.
The need to tune PID constants and visualize how the control system was performing is what led me to develop ViewPort...
Duane- thanks for helping and inspire others with your "DanceBot" (and vision system).
Here are some words of wisdom for balancing bot newbies:
"The bot needs accurate and low-latency measurements of it's orientation. It must drive its wheel's with just the right amount of force. There shouldn't be any mechanical slop in the entire system."
If you're not doing all of the above, your bot won't balance as well as it should...
Hanno
I would agree with this!
Not wishing to contradict Wurlitzer but the "inverted pendulum" nature of the DanceBot must present a significant reflected-inertia to the motor. I doubt that "PI" alone would ever stabilize such a load characteristic. In my (everyday) experience, keeping the "D" term at least an order of magnitude of the "P" term, allows me to increase the "P" term to provide the optimum response. Lastly, I include the "I" term with appropriate limiting to prevent windup.
Regards,
Mickster
I think all the advices given to me above will go a long way with me and others. I know this is not a beginners project, but for me it is a platform. So thank you all.
Mickster
I don't understand the code enough to know what parameters to try adjusting.
Does anyone else see what should be adjusted and where?
I've always been glad when I've taken time to try to understand Hanno's code and I'm sure I'd learn a lot from trying to understand the above method but I don't have the time at the present to do so.
I so see myself building a balancing bot in the near future (I have not previously built one) in order to understand how Hanno's code works. I think understanding Hanno's control algorithm would likely help in several of my current projects.
Mickster