Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 26

Thread: baby steps with the pololu servo controller

  1. #11

    Re: baby steps with the pololu servo controller

    Quote Originally Posted by jes1510 View Post
    Code for an Arduino to talk to a Pololu serial controller via a software serial port:

    Code:
    void servoAbsolute(int servo, int angle)
    {//servo is the servo number (typically 0-7)
    //angle is the absoltue position from 500 to 5500
      digitalWrite(greenLED, HIGH);
    
       unsigned char buff[6];
    
       unsigned int temp;
       unsigned char pos_hi,pos_low;
       
       temp=angle&0x1f80;
       pos_hi=temp>>7;
       pos_low=angle & 0x7f;
    
       buff[0]=0x80;//start byte
       buff[1]=0x01;//device id
       buff[2]=0x04;//command number
       buff[3]=servo;//servo number
       buff[4]=pos_hi;//data1
       buff[5]=pos_low;//data2
    
       for(int i=0;i<6;i++){
          mySerial.print(buff[i],BYTE);
          //Serial.println((buff[i] + '0'), BYTE);    
       }
       digitalWrite(greenLED, LOW);
    }
    
    void servoSpeed(int servo, int value) {
       unsigned char buff[5]; 
       
       buff[0]=0x80;//start byte
       buff[1]=0x01;//device id
       buff[2]=0x01;//command number
       buff[3]=servo;//servo number
       buff[4]=value;//Servo Speed
       for(int i=0;i<5;i++){
          mySerial.print(buff[i],BYTE);
         // Serial.print(buff[i], BYTE);
       }
    }
       
    
    
    void servoSet8Bit(int servo, int angle)
    {//servo is the servo number (typically 0-7)
    //angle is the absoltue position from 500 to 5500
    
       unsigned char buff[6];
    
       unsigned int temp;
       unsigned char pos_hi,pos_low;
       
       temp=angle&0x1f80;
       pos_hi=temp>>7;
       pos_low=angle & 0x7f;
    
       buff[0]=0x80;//start byte
       buff[1]=0x01;//device id
       buff[2]=0x03;//command number
       buff[3]=servo;//servo number
       buff[4]=pos_hi;//data1
       buff[5]=pos_low;//data2
    
       for(int i=0;i<6;i++){
          mySerial.print(buff[i],BYTE);
             
       }
    }
    
     
    void setServoParam(int servo, int data) {
      unsigned char buff[5];
      buff[0]=0x80;//start byte
       buff[1]=0x01;//device id
       buff[2]=0x03;//command number
       buff[3]=servo;//servo number
      buff[4]=data;
      
      
      for(int i=0;i<5;i++){
          mySerial.print(buff[i],BYTE);
          //Serial.println((buff[i] + '0'), BYTE);  
          
      }
    }
    Edit: i don't know if that is useful to you but I have been meaning to post it for a while.

    Hi Jes,

    That is kinda what I am doing.

    btw, I found out a few mins ago that the board ships in Mini SSC II mode. In pololu mode I can move the servo around on the windows box (I used the pololu test program).
    I am sending the exact same thing to the serial port on the linux box.

    It must be a port setting I am not having right

  2. #12

    Re: baby steps with the pololu servo controller

    Quote Originally Posted by MikeG View Post
    I guess your USB to serial adapter is working since it works in Windows? Your using the Pololu Mode? The suggestion above was to use SSCII mode. Have you tried that? (Edit: late on the post)

    According to the manual the protocol is 8N1. Did you setup the serial port correctly? It's hard to help because you have not give much information. We are all just guessing. How about posting all your code.
    I noticed the board comes in MINI mode. yes I have the port set to 8N1 (8 bit, no parity 1 stop bit)

  3. #13
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    174

    Re: baby steps with the pololu servo controller

    I was just commenting your serial code and noticed you're not opening with the O_NDELAY flag...

    If you don't have DCD connected and supported, that's going to be a pretty negative thing.

    The O_NDELAY flag tells UNIX that this program doesn't care about the state of the DCD line. It's great if you've got a terminal with all the lines supported (it tells us if the other side is up or not), and a requirement if you have a modem, but who knows whether the board even brings-up DCD? And if your cable has a DCD wire - If you don't specify the flag, then your process gets put to sleep until the DCD line is brought to the space voltage.

    I stopped reading your uncommented serial code there. If that doesn't work, I'll go comment the rest of it. The other thing _I'd_ do is hook up a cross over cable from one serial port to another, or over to the Windows box and then run RealTerm (free) on the Windows machine and set it up to listen to what Linux is sending. Sometimes you get kernel messages out on the first terminal, and that can really ruin your day.

    >> I hooked it up to a Linux box (both on a serial port

    >> [from code]
    #define DEVICE "/dev/ttyUSB0"

    I hope you didn't do that then, right?
    I Void Warranties´┐Ż

  4. #14

    Re: baby steps with the pololu servo controller

    Quote Originally Posted by Adrenalynn View Post
    I was just commenting your serial code and noticed you're not opening with the O_NDELAY flag...

    If you don't have DCD connected and supported, that's going to be a pretty negative thing.

    The O_NDELAY flag tells UNIX that this program doesn't care about the state of the DCD line. It's great if you've got a terminal with all the lines supported (it tells us if the other side is up or not), and a requirement if you have a modem, but who knows whether the board even brings-up DCD? And if your cable has a DCD wire - If you don't specify the flag, then your process gets put to sleep until the DCD line is brought to the space voltage.

    I stopped reading your uncommented serial code there. If that doesn't work, I'll go comment the rest of it. The other thing _I'd_ do is hook up a cross over cable from one serial port to another, or over to the Windows box and then run RealTerm (free) on the Windows machine and set it up to listen to what Linux is sending. Sometimes you get kernel messages out on the first terminal, and that can really ruin your day.

    >> I hooked it up to a Linux box (both on a serial port

    >> [from code]
    #define DEVICE "/dev/ttyUSB0"

    I hope you didn't do that then, right?
    Hey Lynn,

    I realized the ndelay just a few mins ago... I changed that, BUT still no cigar
    (I have to build another x-over cable, *lol* I cleaned out the garage this summer and found one and was thinking "when would I ever use that again?"
    Last edited by csdude; 01-18-2010 at 01:49 AM.

  5. #15

    Re: baby steps with the pololu servo controller

    alright,

    I have some servo's moving... with just some wild guesses as parameters.

    However I it only works if I take the DTR/RTS reset jumper off. (that probably means my port is keeping and DTR and RTS high and constantly resets the port? If I take the jumper off it works, but of course that way I can't reset the board.

    Another thing I have to figure out is what exactly goes into byte 5 and 6 of the "pololu" command x04
    (and the the other 5 commands for that matter)

    thanks all for helping me so far!

    Ron

  6. #16
    Join Date
    May 2008
    Location
    TN
    Posts
    853
    Images
    99
    Rep Power
    71

    Re: baby steps with the pololu servo controller

    If you are talking about the absolute position command then that is the first one in the code that I posted ("servoAbsolute"). Byte 5 is the high byte of the servo positiopn. Byte 6 is the low byte.
    "If A is a success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut."
    -
    Einstein

    Don't be a HelpVampire

  7. #17

    Re: baby steps with the pololu servo controller

    Quote Originally Posted by jes1510 View Post
    If you are talking about the absolute position command then that is the first one in the code that I posted ("servoAbsolute"). Byte 5 is the high byte of the servo positiopn. Byte 6 is the low byte.
    Right, the absolute position; let's see if I have it right.

    So neutral/center is at 1500 μs and that is 3000 in 'pololu steps'. According to the specs the resolution is 0.5 μs per 0.05 degrees. So 180 degrees would be 1800μs or in pololu steps 3600

    So if I go from 90 degrees left to center to 90 degrees right:

    600 μs - 1500 μs - 2400 μs or
    1200 - 3000 - 4800 in 'pololu steps'
    0x4b0 - 0xbb8 - 0x12c0 (same thing but hex)

    So if I do something like:

    for (i = x4b0; i <= 0x12c0; i++)
    port-write("0x80 0x01 0x04 0x00 MSB(i) LSB(i)") // not actual code

    than the servo would go from 90 degrees left to 90 degrees right, correct?

    edit: Of course I could just move it to the left, than center and than right, but that way you can do a 'sweep'

    or do something like:
    for (i = x4b0; i <= 0x12c0; i+=10)
    port-write("0x80 0x01 0x04 0x00 MSB(i) LSB(i)") // not actual code

    to make 5 degree steps
    Last edited by csdude; 01-18-2010 at 09:54 AM.

  8. #18

    Re: baby steps with the pololu servo controller

    hello again,

    there is no way to test to see if the servo is done with executing a command you sent to the servo board, is there? (I see an echo of the command sent, but that is what it is, an echo.. it is not sent after the servo itself was done)

  9. #19

    Re: baby steps with the pololu servo controller

    General hobby RC servos do not provide position feedback. If you know the angular velocity you should be able to make a good guess. A quick Google search will turn up a lot of info if you want to try reading the voltage across the internal POT.

    This is one of the main reasons I (as well as others around here) use Dynamixels.
    Last edited by MikeG; 01-18-2010 at 06:34 PM.

  10. #20
    Join Date
    May 2008
    Location
    TN
    Posts
    853
    Images
    99
    Rep Power
    71

    Re: baby steps with the pololu servo controller

    Look in the tutorials section for a tutorial I wrote on how to modify a hobby servo as MikeG mentioned.

    As for the pololu controller, there is no way to get feedback when the controller has finished a move. The best you can do is a time based guess.
    "If A is a success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut."
    -
    Einstein

    Don't be a HelpVampire

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. RC & Serial Servo Controller Kit
    By Al1970 in forum Garage Sale
    Replies: 0
    Last Post: 01-10-2009, 12:39 AM
  2. Question(s) Pololu 3A Motor Controller with Feedback
    By kankatee in forum Arbotix, Microcontrollers, Arduino
    Replies: 4
    Last Post: 12-22-2008, 07:53 PM
  3. Controlling Servos with a servo controller
    By bodhibuilder in forum Arbotix, Microcontrollers, Arduino
    Replies: 25
    Last Post: 09-29-2008, 11:07 AM
  4. Question(s) servo and motor controllers
    By csdude in forum Arbotix, Microcontrollers, Arduino
    Replies: 7
    Last Post: 06-15-2008, 08:23 PM
  5. Kondo web page translated.
    By Droid Works in forum Humanoids, Walkers & Crawlers
    Replies: 4
    Last Post: 10-06-2007, 05:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •