Awhile ago I ported some of the Mechbrat code over to the Arduino environment, so since hopefully soon we will have BotBoarduino JR boards available, I thought it would be great to have the Brat running on that board
I think I have most of the basics working now as you can maybe see in this short tease poor quality video:
I will post code for this soon. But first need to get it cleaned up.
With the help of Devon, found and hopefully resolved some issues.
a) Found the servos were really jumpy - Found problem with PS2 library where the writes to the IO pins was not atomic and was walking over the changes made by the servo library. I made a temporary fix to the library and a new version of the library was released by the developer with the fixes.
b) Found I was running out of memory on my old code. The problem was the command lists were wasting a lot of memory and were in normal data space. Changed to conserve space and to put into PROGMEM, so went from the main data size of over 1800 to something a little over 500 bytes. Hint - if your program is not working right and you can not figure out why… Try building verbose and then run avr-size on the generated file to see how much space you are using…
I thought it was about time that I posted an update for this project.
I decided to rework the project some and turn some of my SSC-32 like timed/group move code into a library. In my first pass I did all of the updating of the servo locations in an independent library that used a timer interrupt to do the updates, which was inefficient and not as smooth as it could be. So in this pass I integrated my code directly into the servo library. If there is some timed move in operation, it now updates the servo pulse width right after the end of the previous pulse, so there are no extra interrupts and I think it works smoother. This is still a Work In progress. but in case anyone would like to try it out, Here is the library and my current Brat code…
Warning the ServoEx adds some memory usage. I believe it add 3 extra words for each possible Servo…
If any one is interested, I will post more detailed information about both the library and the current state of the Brat code.
What I meant was that before,I used the normal servo library, which every 20ms it would generate the pulses for the different Servo pins. Plus I had some additional code that used a timer and on each timer interrupt, I would check my own set of tables and see if I had a timed move in progress. If I did, I would update those servos, by calling off to servo.write or servo.writeMicroseconds. This added additional overhead and the changes were not synchronized with when the pulses were generated.
With my ServoEx code, when you commit a move to a new location with a time value, it calculates how much of a difference should happen during each 20ms pulse cycle and after it brings the pulse low for the servo, it updates the value by that amount, until it gets to the new desired location.
The timed moves can be done two ways. By using the new class with a global instance (could be just an api…) or I added a simple one servo timed move to the ServoEx class (which right now is a simple shorthand of using the other class…
That is, you can do something like:
ServoGroupMove.start();
g_aServos[RHS_I].writeMicroseconds(g_RHipServoMS);
g_aServos[LHS_I].writeMicroseconds(3000-g_LHipServoMS ); // invert
ServoGroupMove.commit(250);
Which is used in the brat to move the hips when you use the left joystick on the PS2… Note: g_aServos is an array of servo objects.
As I said I also provided a quick and easy way… Where the above could have been written as:
g_aServos[RHS_I].move(g_RHipServoMS, 250);
g_aServos[LHS_I].move(3000-g_LHipServoMS, 250 ); // invert
This may not work out identically as the two are not committed at the exact same time, but I doubt you will notice.
Also I see that I want to update this code anyway, as I am using Microseconds, which will not use the inherent servo offsetting code that I get when I use degrees. I do this for degrees by sliding the Min and Max values for a servo which the underlying map function will use in the conversion from degrees to microseconds.
Yep, the trick may work on the ChipKIT32, I will try it out sometime soon. On that front I would like to get my Hex code to run on the UNO32. I think I now have a working PS2 on it. Need to do a few more things and then try it out. An 80mhz processor should be fun!
But back to the topic. Arduino 1.0 was released But this requires some changes to make my current stuff to work. Some simple things like they renamed WProgram.h to Arduino.h so needed to update library files.