Trossen Force Sensor  Top Banner
Results 1 to 5 of 5

Thread: Controlling AX-12 via Keyboard

  1. #1

    Controlling AX-12 via Keyboard

    Hi everyone!

    I'm a newcomer to robotics and am trying to understand my 'Arbotix Robocontroller Starter Kit' from Trossen Robotics. Currently, I'm finishing a BS in Computer Science, but am woefully ignorant when it comes to hardware.

    I would like to use the arrows on my keyboard to wirelessly control a single AX-12 servo motor on the robocontroller through the two Xbees.

    Right now, I am able to upload an Arduino program to the Arbotix robocontroller through the ISP programmer that came with the kit. The program moves the AX-12 automatically, but I would like to move it in real time with my keyboard. I also went through the Xbee tutorial on this site. I used the X-CTU software and the 'Xbee Explorer USB' to connect the Xbees to my computer. Unfortunately, I couldn't find the xbee.py files from the Xbee tutorial. The link wasn't working for me.

    Any information on how to communicate with the Xbees and the robocontroller, in real time, would be greatly appreciated.

    tl;dr
    Can I control an AX-12 Servo with my keyboard and the 'Arbotix Robocontroller Starter Kit'?


    Thanks for your help!

  2. #2
    Join Date
    Dec 2007
    Location
    Whidbey Island, WA
    Posts
    1,617
    Images
    432
    Rep Power
    76

    Re: Controlling AX-12 via Keyboard

    Hey cyber penguin...

    I got help creating something that doesn't exacly do what you want, but does something similar to what you are looking to do.

    http://forums.trossenrobotics.com/sh...4430#post44430

    It takes keyboard commands and has the arbotix do stuff...I am sure you can figure out how to make it do what you want by looking over the code. i am not positive, but I think the code might need slight modification to work with an arbotix.

    Hope this helps.

    DB

  3. #3
    Join Date
    Sep 2010
    Location
    ಠ_ಠ
    Posts
    1,166
    Images
    25
    Rep Power
    47

    Re: Controlling AX-12 via Keyboard

    The XBee Explorer should show up on the PC as a plain old serial port (e.g. COM4 on windows or /dev/ttyUSB0 on linux). The PC side software will just be a program in any language you want to connect to the serial port and send whatever you want to the arbotix as a control (press 'w' and send the character 'w' or some other sequence of bytes over the serial port through the XBee to the arbotix which then interprets it and does something).

    The arbotix side code will simply read from the UART (generically referred to as a 'serial port' or worse as an 'RS-232 serial port') the XBee is connected to and then do whatever you want with it. The code darkback linked should be a decent base if you don't already have an example using the arbotix pose code (poses in a header file created by pypose.py).
    Please pardon the pedantry... and the profanity... and the convoluted speech pattern...
    "You have failed me, Brain!"

  4. Trossen Dynamixel High Thread Banner
  5. #4

    Re: Controlling AX-12 via Keyboard

    Thank you for your quick responses!


    Using them, I've figured a few things out. I had never used serial communication before, so it took some time to understand. Anyway, here's what I've done for anyone curious:

    1. Plugged in the Xbee and Xbee USB Explorer into my computer. On my computer its 'COM6' according to the Device Manager.

    2. I installed python and used the following code in the Python GUI:
    Code:
        >>> import serial
        >>> ser = serial.Serial('COM6', 38400)
    3. I then uploaded the following code to the Arbotix robocontroller:
    Code:
        #include <ax12.h>
        #include <BioloidController.h>
    
        BioloidController bioloid = BioloidController(1000000);
        int i;
        int val;
    
        void setup(){
             i = 0;
             val = 0;
             Serial.begin(38400);     // connect to the serial port
        }
    
        void loop(){
              val = Serial.read();     //read in serial input
    
               if (val == '1') {        //if '1' move the motor
                     while(i<1024){
                       SetPosition(1,i);
                    i = i + 1;
                  }
                }
        
                i = 0;
        }
    4. I then typed "ser.write('1')" into the python GUI and ... nothing happened.

    5. I figured this was because ser.write('1') may not have been seen by the robocontroller, so I wrote the following

    Code:
        >>>while 1:
               ser.write('1')
    Now the motor twitches every so often. It's not much, but it's progress!

    Its not perfect yet, but I'm going to continue working on it. Anyway, I wanted the thank you again for your help. Also, any other advice you might have would be greatly appreciated.

    Specifically, if you know how to make the servo motor rotate 360 degrees instead of just twitching randomly.
    Last edited by CyberPenguin; 03-08-2012 at 07:45 PM.

  6. #5
    Join Date
    Sep 2010
    Location
    ಠ_ಠ
    Posts
    1,166
    Images
    25
    Rep Power
    47

    Re: Controlling AX-12 via Keyboard

    Might want to wait a bit between calls to SetPosition(1,i), since the servo can only respond so quickly to incoming packets. You could also try reading the "Moving" register of the servo to be sure you don't attempt to give it a new goal position until it has finished reaching its current goal position. The AX-12 pdf on the trossen shop's site is quite useful and the Robotis support site has more up-to-date info on dynamixel servos (Product Information->Dynamixel->AX-Series). Don't have much experience with python, but the snippet you posted does look correct to my inexperienced eyes.

    Code:
    #include <ax12.h>
    #include <BioloidController.h>
    
    BioloidController bioloid = BioloidController(1000000);
    int i;
    int val;
    
    void setup(){
         i = 0;
         val = 0;
         Serial.begin(38400);     // connect to the serial port
    }
    
    void loop(){
        val = Serial.read();     //read in serial input
    
        if (val == '1') {        //if '1' move the motor
            while(i<1024){
                SetPosition(1,i);
                i = i + 1;
                delay(10);  // just use a delay without reading the moving register
    // or
    //            while (ax12GetRegister(1, AX_MOVING, 1)) {delay(3);} // delay length probably ok, but may not work
            }
        }
        i = 0;
    }


    Off topic, but I seem to be having a bit of trouble again with copy+pasting code blocks into the reply text box. Not sure if it is Firefox or not (currently 10.0.2, but had the problem with at least 4 and 5 as well). If I add the close tag before I paste, the tag ends up being behind the pasted text with the last few lines of code inaccessible. If I do not add the close tag until after pasting it seems to work fine unless I want to remove the space between the open tag and the first line of the copied code, at which point it deletes most whitespace (line breaks, tabs, and preceeding spaces). I guess it is somehow grabbing the old code tag when I copy, because copying the code to gedit and then copying that to the text box causes no problems at all.
    Please pardon the pedantry... and the profanity... and the convoluted speech pattern...
    "You have failed me, Brain!"

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. C# code for controlling servo with keyboard
    By bluegear in forum Software and Programming
    Replies: 15
    Last Post: 09-10-2010, 05:25 PM
  2. Question(s) Controlling SSC-32 with Atmega 168
    By sam in forum Software and Programming
    Replies: 0
    Last Post: 03-15-2010, 06:25 PM
  3. Controlling an airsoft gun from SSC-32
    By FlowbotX in forum Mech Warfare
    Replies: 10
    Last Post: 02-25-2010, 03:51 PM
  4. controlling biped brat
    By matterest in forum Mech Warfare
    Replies: 30
    Last Post: 02-04-2010, 02:40 PM
  5. Question(s) Controlling servos using Midi...help
    By darkback2 in forum Software and Programming
    Replies: 38
    Last Post: 07-29-2008, 03:17 AM

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
  •