Next large robot



  • I’ve been spending a lot of time on the P2 forum and learning C programming using FlexSpin. That’s a great tool and works well. To learn C I am spending time on the Parallax Tutorials which has a very nice C tutorial written for the P1. It’s been fairly easy to translate the lessons over to the P2 so far. The P2 C setup has a lot of add-ons for math so last night was spent writing some simple programs to enter an angle and output the sin value. I was getting lots of errors before I realized the sin() function used rads instead of angles for input. After that it got much easier. Today I want to start converting my Inverse Kinematics formulas from the P1 program over and see if I can get them running also.
    C hasn’t been too bad to learn so far but I’m still in the very basic stages of it, I’m sure it will get more interesting soon! As it is I tend to make a lot of stupid mistakes that keep things from compiling...
    Still looking for a serial communications object that can handle several separate input/outputs. I’ll have to look at the P1 versions of these objects to see if I can convert one over to the P2 if one doesn’t show up by the time I need it. The other thing that needs setting up is the XBee radio, will need to get a interface board since none of the P2 boards have that incorporated and create a P2 object to interface. Lots of stuff to do still but it’s all fun.


    PS. I sold my big metal lathe which required dismantling the hexapod as it was in the way for getting the lathe out of the basement. Finally got the robot back together again (lots more space for testing the legs now!) so hopefully I’ll be able to start testing with the P2 board before too long.
  • Fun times learning new P2 language, specifically C for the P2.
    My first adventure was converting the existing Inverse Kinematics (IK) formulas into something that would compile under FlexSpin. First off I had to remind myself about how I went about coming up with the original equations. That required some digging and finding the PDF (see attached) with my calculations.
    Next step was entering the equations and lots of work getting the syntax right!
    /* Test code for IK entries - fixed inputs for testing purposes */
    #include <stdio.h>
    #include <math.h>
    #include <propeller.h>
    #include <simpletools.h>
    double coxaLength = 2.5;
    double femurLength = 6.0;
    double tibiaLength = 25.0;
    #define LEDdata  54
    #define LEDclock 52
    void main()
      float degreeValue;  
      degreeValue = 45.0;
      /*  getsine(degreeValue); */
      /*  legIK(0.0, 28.0, 11.0); */
    double to_degrees(double rad)
      	return rad * 180.0 / PI;
    double to_radians(double deg)
      	return deg * PI / 180.0;
    void legIK (double IKx, double IKy, double IKz)
      	double L1, L, C, IKb, IKb1, IKb2;
      	double IKfemurAngle, IKtibiaAngle, IKcoxaAngle;
      	L1 = sqrt((IKz*IKz) + (IKx*IKx));
    	L = L1 - coxaLength;  
      	C = sqrt((IKy*IKy) + (L*L));
      /* IKb = acos(((femurLenth^2 + C^2) - tibiaLength^2) / (2 * femurLength * C))  */
      	IKb = acos(((femurLength*femurLength) + (C*C) - (tibiaLength*tibiaLength)) / (2.0 * femurLength * C));
    	IKb2 = atan(L / IKy);  
      /* IKb1 = acos((tibiaLength^2 + C^2 - FemurLength^2) / (2 * tibiaLength * C))  */
      	IKb1 = acos(((tibiaLength*tibiaLength) + (C*C) - (tibiaLength*tibiaLength)) / (2.0 * tibiaLength * C));
      	IKfemurAngle = (IKb + IKb2) * (180.0 / PI);
     	IKtibiaAngle = (IKb2 - IKb1) * (180.0 / PI);  
     	IKcoxaAngle = atan(IKz + IKx) * (180.0 / PI); 
      	printf("L1 = %lf\n", L1);
      	printf("L = %lf\n", L);
      	printf("C = %lf\n", C);
      	printf("IKb = %lf\n", IKb);
      	printf("IKb2= %lf\n", IKb2);
      	printf("IKb1 = %lf\n", IKb1);
      	printf("IKfemurAngle = %lf\n", IKfemurAngle);
      	printf("IKtibiaAngle = %lf\n", IKfemurAngle);
      	printf("IKcoxaAngle = %lf\n", IKcoxaAngle);
    I got everything up and running faster than I expected, the C math library was much easier to use than floating point on the P1! The test code outputs to a windows terminal window with the calculation results. I'd like to output to the Propeller Serial Terminal (PST) window if I can figure out how to get FlexSpin to change its default output.
    Now I'm working on getting the robot RGB troubleshooting LEDs to work under P2. The P1 object for the LPD8806 is a combination of Spin and pasm and I'm pretty rusty on assembly. I've been trying out a Spin only bit-banged approach but it isn't working quite right yet. The LPD8806 LED Driver chip appears to be unique and there isn't much out there, even the datasheet doesn't show the timing requirements for the chip. The only other driver I found on-line was written in C for an Arduino so not much help there. I'm about ready to give it up and switch over to the WS2812B RGB modules that Parallax sells. There are several P2 drivers already developed for it.
  • I think if you leave off the '-t' parameter in the command line P2load will not start the build in terminal and you can use the Propeller Terminal as you did with the P1.

  • I got a lot of help from the folks on the P2 forum and especially JonnyMac in coming up with a driver for the LPD8806 RGB controller. The driver works great so it's time to move on to the next item on the list.
    Next is getting a multi-port serial device set up. The P1 master code uses 2, 4 port serial objects. There are 8 serial lines being used; 1 for master to leg controllers (one way comms only), 6 receive lines from each leg controller to the master (one way comms also), and 2 way comms via the PropPlug (mainly for troubleshooting).
    I started fiddling with a simple serial driver, jm_serial.spin2, unfortunately I managed to break it and now it isn't responding. JonnyMac recommended that I look into his FullDuplexSerial code as he set it up better for handling multiple ports. So its off to reviewing more code and seeing what it might take to allow it to handle more lines. I have seen that the P2 Smart Pins capabilities are pretty nice and can greatly reduce the amount of setup code needed for tasks like this. Study time again!
    Nothing else to update on, still haven't quit on this project!
Sign In or Register to comment.