DanceBot Questions
Rick Brooks
Posts: 67
I've been reading "Programming and Customizing the Multicore Propeller Microcontroller" chapter 6 on the DanceBot.
It appears that the source code listed for chapter 6 is the same as is listed for chapter 7.· Specifically, on page 255 there is a bit of code that gives a command "bal.do(10,10,0)" and I don't see any spin programs listed that have a "bal" object reference.
It is obvious how the gyroscope is mounted from the photos.· On the other hand, mounting the accelerometer is not shown.· The code indicates that only the x axis is used.· I don't think that the accelerometer is mounted with the x axis straight up.· How should it be mounted?
For the encoders, both are wired and, I think, both are being read.· Which one (right or left side) is being used for the PID input?
Finally,·I have never used the LMD18200 motor controllers.· Do you just glue them to some surface and run short wires from the pins, or is there a better way of mounting them to the Proto Board?
That is enough questions for now.
········ Rick Brooks
It appears that the source code listed for chapter 6 is the same as is listed for chapter 7.· Specifically, on page 255 there is a bit of code that gives a command "bal.do(10,10,0)" and I don't see any spin programs listed that have a "bal" object reference.
It is obvious how the gyroscope is mounted from the photos.· On the other hand, mounting the accelerometer is not shown.· The code indicates that only the x axis is used.· I don't think that the accelerometer is mounted with the x axis straight up.· How should it be mounted?
For the encoders, both are wired and, I think, both are being read.· Which one (right or left side) is being used for the PID input?
Finally,·I have never used the LMD18200 motor controllers.· Do you just glue them to some surface and run short wires from the pins, or is there a better way of mounting them to the Proto Board?
That is enough questions for now.
········ Rick Brooks
Comments
Whew- lots of questions- let's see how I do..
I'm going through the DanceBot code to add some comments and make it easier to use- should finish end of this week- I'll make a post here.
You should mount the accelerometer so that it gives positive readings when you tilt the bot one way, and negative when you tilt it the other way. At rest, it should read close to 0. The Kalman Filter will fuse the output of this sensor with that from the gyroscope to get a good signal for balancing. Only the left motor's encoder is connected- I blew out the led on the right side early on- it ends up making the software a bit easier.
I screwed the LMD18200 together and hot-melt glued them to the acrylic tube. I ran wires to the ProtoBoard. They're quite big, so I couldn't fit them onto the Protoboard.
Good luck!
Hanno
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Co-author of the official Propeller Guide- available at Amazon
Developer of ViewPort, the premier visual debugger for the Propeller (read the review here, thread here),
12Blocks, the block-based programming environment (thread here)
and PropScope, the multi-function USB oscilloscope/function generator/logic analyzer
Thanks for the response.
Studying DanceBot has presented interesting solutions to some problems that I had not previously anticipated.
I look forward to seeing the rest of the code.
··········· Rick Brooks
I went through the code (good memories )
I've added lots of comments and removed code that wasn't being used.
The "do(speed,rotation)" function was in the "dancebot.spin"- it keeps the bot balanced while allowing you to specify its speed and rotation. The main loop of that file uses vision to find an item and then steers the bot there by continually calling the "do" function.
I've updated the "conduit" file with the file from the latest ViewPort- other than that the code from the book works fine with the latest ViewPort.
I'm working on getting the new code onto the book's ftp server, for now the archive containing all code is here:
hannoware.com/dancebot/code.zip
Hanno
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Co-author of the official Propeller Guide- available at Amazon
Developer of ViewPort, the premier visual debugger for the Propeller (read the review here, thread here),
12Blocks, the block-based programming environment (thread here)
and PropScope, the multi-function USB oscilloscope/function generator/logic analyzer
Thanks for the update.· The dancebot.spin code is much easier to read, now.· I see where the "do"·method comes in and controls the robots movement.· I never got that far in the earlier dancebot code.
I think that I have all of the parts to building a balancing robot, but I am more interested in·understanding the process of development, rather than building a finished robot.· The concept of a "hybrid fuzzy logic cascading PID controller" fascinates me.
I'll keep you posted on my progress.
······· Rick Brooks
·
I have been using the Dancebot code as a learning aid. However, I am having a huge problem in understanding how the Kalman filter and the Fuzzy logic works. I have found some tutorials on the internet addressing these subjects, and I believe I sort of understand the Fuzzy logic. But, the Kalman filter is really throwing me for a loop. From what I have read about it on the internet, the Kalman Filter will get rid of "noise". However, Hanno Sandar is using it to "meld" the inputs of the accelerometer and the Gyro. Does anyone have any suggestions?
I wrote a bit about the control algorithm in 2 chapters of the Propeller book- see my signature. Getting a bot to balance in place for several minutes is comparatively easy and only requires a simple P, or PD filter. After months of experimenting and reading about other attempts I concluded I needed a full blown cascading pid controller- which I attempted to simplify using fuzzy logic. The Kalman Filter is separate from the controller- it fuses signals from two sensors (one of which is the derivative of the other) into a very accurate reading. Have a look at ViewPort- it includes a fuzzy logic visualizer, sample, documentation. Links in my signature...
Hanno
When I activate my robot, it acts as though it would balance on a curved surface (curved up like a smile). When placed on a flat surface, it will lean a little one way or the other, and the robot speeds towards the lean. However, the lean is always ahead of the robot's speed. So, it just travels faster and faster untill it falls over. I have experimented with every one of the variables within the "setmap" statements and have had no success. Does anyone have any suggestions? I am at my wits end.
I am not as far along as you. But, I did notice a variable "tiltOff" that may be what you are looking for.
"tiltOff: offset in tilt- calibrated so tilt reads 0 when balanced"
Rick Brooks
As others pointed out, there may be multiple things going on:
- "P" constant of PID controller set too low. Tuning this requires experimentation (or lots of math). Keep setting it higher until it oscillates.
- "0" point not calibrated correctly. "tiltOff" should be set to a value so that "tilt" reads 0 when balanced straight up.
- your bot is not fast enough. Are you using similar wheels, motor, batter, controller to mine?
Hanno
I have tried varying both the proportional and integral values in an attempt to get this thing to balance, but it still acts like the speed is too slow. I am using all the parts listed in the book “Programming and Customizing the Multicore Propeller Microcontroller” with exception of the wheels. I don’t think Lynxmotion offers the 3.6 inch diameter wheels anymore, so I had to used the 2.75 inch wheels. I thought that the wheel size might be the cause of the problem, so I made a pair of 3.6 inch wheels out of plywood (with a rubber band for the thread) but it still acts the same.
So, I will continue to experiment. I can appreciate how Hanno’s kid learned to balance before his robot did!
You're very welcome.
In case you or anyone else is interested, I adapted the original DanceBot code to use a Memsic2125 accelerometer.
I personally haven't made a balancing robot but it's on my todo list.