PS2-Hexapod code problem

Hello,

I have written a simple program for controlling my Lynxmotion AH3-R hexapod (Botboarduino/SSC-32). Right now all it does is make the robot walk uncontrolled in a straight line, but it does that OK. I now want to add control using the Lynxmotion PS2 wireless controller, and then gradually add to the complexity of the robot’s motions. I tried using the PS2X_Example from the Arduino Libraries folder as an example. Actually, all I did was to try to use the code from the example’s setup() routine to create a function setupPS2(), which I hoped to use. I modified the pin numbers so that that example runs OK on my robot. After some fooling around I was able to create files for that code to include in my main .ino file which compile OK and which allow the robot to walk OK. However, when I attempt to apply that function, setupPS2(), in my main code, the code fails to run properly. It recognizes the PS2 OK, but the loop() function does not run properly. With that setupPS2() line commented out the code runs OK. Any thoughts on what is wrong?

I’ve attached my code in case anyone would like to look at it, or even use it. My robot is set up with all the legs normal to the robot’s center line in the reference position, like a BH3 or AH2. It also reads and uses the SSC-32 initial-pulse-width registers. The code for reading those registers could be commented out if one wanted to use 1500 muSec as references.
PS2Hexapod15Jan2014.zip (4.22 KB)

Nope, but Jeffrey is taking a look at the PS2 and will offer his insight when he returns. In the meantime:

Check that the PS2 example works when you have it connected to the BotBoarduino (and connect the BBuino to the computer via USB). Once you have everything working, check the serial terminal in Arduino since there should be values being output. This will ensure you have it all connected properly. Follow the instructions in the sample code as to which pins to use. You can then pick and choose which code from the PS2 example to use with your robot.

Hi,

The example works OK on my BotBoarduino, and prints out nice values on the monitor when I push various things on the PS2.

Ted

Hello again,

As an experiment I tried using hardware serial rather than the software serial. I thought this would indicate whether or not the problem lay in the software serial. Unfortunately, the results were the same. The robot ran OK if I did not setup the PS2. However, if I setup the PS2 the program runs, but not properly. My program breaks the gait into phases, and, using software serial (or just serial), generates a complete SSC-32 command for each phase, a command positioning each of the 18 servos for each phase. If I setup the PS2, this command is only partially created, moving only a few of the highest-numbered servos. Thus the serial or software serial print statements in loop() are not running properly if I setup the PS2.

Ted

Which version of the PS2 library did you use? The main one from Bill Porter, or the version that is up on the Lynxmotion, that I hacked on awhile ago?

Unfortunately I don’t have time to go completely through your code base. But will give a few thoughts:

  1. The PS2 code base works, using a software SPI function, that sends some bytes and receives some back. The more it receives back, the more likely it will delay things. So by default, I would turn off Pressures and Motors (last two parameters to init), unless you are actually using these values.

  2. Some versions of the library had some issues with Interrupts and IO data being corrupted. I fixed that awhile ago in his library, but some others were having issues and at one point those changes were backed out…

  3. In cases like this I also wonder about how much memory are you using. In particular you only have 2K of memory for all variables, Stacks, queues, and the like. All of your variables and arrays are held in this as well. Could also hit some threshold. Especially since you are also building a complete string for all 18 servos. You could just as easily print each part of the command out as you generate it…

  4. Probably works OK, but you keep redefining the variable command to itself. I will be honest and say I don’t typically use the string library, but don’t see any benefit from the function formcommand returning back the string, as it is simply using a global variable and then returning that global variable that you reassign back to the global…

Kurt

Thank you for all your thoughts. I appreciate your inputs. I’m very new to this system, so I would not be at all surprised if I can improve the way I’m doing lots of things. I’ll experiment along the lines you suggested and let you know how I make out.

Ted

Hi Kurt,

I implemented a lot of your suggestions. I printed the servo commands directly without creating a string to send, and I worked on reducing the amount of memory used for variables. I made so many changes that I can’t point to which were most important. None solved my problem. Finally, I changed the way I was determining how long to wait before sending a new set of servo-positions to the SSC-32. At first I read the SSC-32 register indicating when a move was completed. I abandoned that and instead measured the time the code required, and subtracted that time from the time I specified for completing the servo motion. Then I used a delay for that remaining time, and that works very well. Problem solved! For some reason, reading the SSC-32 register indicating move status was unreliable. It worked sometimes, but not always.

Thank you for your help.

Ted

Seems like Kurt covered all the points I would have asked, and even more: thanks Kurt!

Like Kurt said, seems like an I/O problem. Perhaps moving the SSC-32 (software) serial from pins 12-13 to pins 10-11 might help.