Results 1 to 3 of 3

Thread: Arbotix FTDI command problem

  1. #1
    Join Date
    Feb 2010
    Location
    Northern, VA (Fredericksburg)
    Posts
    104
    Images
    10
    Rep Power
    34

    Question Arbotix FTDI command problem

    I have been having a strange issue with my Arbotix while running my current tests. I used a slightly modified code from Darkback2's code from here:

    http://forums.trossenrobotics.com/showthread.php?t=4434

    I basically just cut out the python stuff and was using the serial monitor to send commands, seems pretty simple. So here is the problem: I have to send something twice to get the arbotix to respond, both in the serial monitor and for the servo to move. Basiclly it is ignoring every other command. I am using a FTDI to communicate with the arbotix and I don't have a Xbee installed.

    Here is the code:

    Code:
    #include <ax12.h>
    #include <BioloidController.h>
    
    BioloidController bioloid = BioloidController(1000000);
    
    void setup()
    {  
        // need to start the serial port
        Serial.begin(38400);
    
        // recommended pause
        delay(100);
    
    }
    
    void loop()
    {
        char cmd[8];
        int startByte = 0;
        
        // if there are bytes waiting on the serial port
        if(Serial.available() > 0) {
          // read the incoming byte
          startByte = Serial.read();   
        } // end Serial.available()
        if(startByte == 'p') {
          // get the command from the serial port
    
    // START FERGY EDITS HERE
          while(Serial.available() < 8); // wait for data to arrive, do nothing      
          for(int i=0;i<8;i++){
            cmd[i] = Serial.read();
          } //this creates an array that takes in the data from the serial port
    // END THE FERGY EDITS
          
          // convert command to two numbers
          int servoNum = 0;
          int servoPos = 0;
          
          servoNum = (cmd[0]-48)*10 + (cmd[1]-48);
          servoPos = (cmd[3]-48)*1000 + (cmd[4]-48)*100 + (cmd[5]-48)*10 + (cmd[6]-48);
          
          //sets servo position using 2 numbers one for servo, other for position.  currently not working.
         SetPosition(servoNum,servoPos);
          
          // debug
          Serial.print("cmd array:");
          for(int i=0;i<8;i++){
            Serial.print(cmd[i]);
          }
          Serial.println("----");
          Serial.print("servoNum:");
          Serial.println(servoNum);
          Serial.print("servoPos:");
          Serial.println(servoPos);
          
        }
          
    } // end loop()
    After uploading the code to the arbotix, I open the serial monitor and type a command. Usually something like: "p01,0500" - the command shows up in the lower serial monitor box, but nothing else happens. Then I enter the exact same line and I receive a response from the arbotix over the serial monitor and the servo jumps to that position. I can continue this for a while, entering two commands for every 'received' command.

    Any suggestions would be greatly appreciated :*)

    Cheers,
    Scott

  2. #2
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    127

    Re: Arbotix FTDI command problem

    That code assumes a newline (or any character really) at the end of each command. What you are seeing is that it blocks on the line "while(Serial.available() < 8);" until the first character of the second command arrives (at which point it consumes the "p" character and so the second command becomes garbage that is ignored).

    -Fergs

  3. #3
    Join Date
    Feb 2010
    Location
    Northern, VA (Fredericksburg)
    Posts
    104
    Images
    10
    Rep Power
    34

    Re: Arbotix FTDI command problem

    Would it be better to add a extra characater to my command (EX: p01,0500x) or change the code
    "while(Serial.available() < 8);"
    to

    "while(Serial.available() <= 8);"
    and use the normal command? Or does it not matter much?

    Thanks again for your help Fergs!

    Cheers,
    Scott

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. ArbotiX-ROS Roadmap
    By lnxfergy in forum ROS - Robot Operating System
    Replies: 10
    Last Post: 02-10-2011, 10:50 AM
  2. ArbotiX ROS Package 0.3.0
    By lnxfergy in forum ROS - Robot Operating System
    Replies: 233
    Last Post: 02-06-2011, 11:36 AM
  3. Question(s) A question about Arbotix python library
    By zzl1007 in forum Arbotix, Microcontrollers, Arduino
    Replies: 18
    Last Post: 11-24-2010, 02:18 PM
  4. Question(s) Newby Arbotix hassles
    By Slugman in forum Robot Computers
    Replies: 29
    Last Post: 11-15-2010, 08:52 AM
  5. Question(s) ArbotiX, XBee and The FTDI Basic Breakout
    By Robonaut in forum Arbotix, Microcontrollers, Arduino
    Replies: 4
    Last Post: 02-27-2010, 08:22 PM

Tags for this Thread

Posting Permissions

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