PDA

View Full Version : [Question(s)] Controlling Dynamixel with Arbotix Commander



Buell24
01-02-2011, 07:48 AM
I,m trying to control one AX12+ Servo attached to an Arbotix Robot Controller through an Arbotix Commander Joystick. What I want to do is to use the values of the Joystick (-100 - 100) to move the servo back and fourth with different speed according to the value of the Joystick. My problem is, that I have no Idea how to do that. Can anybody help me doing this? I would be very thankful for any demo code.

RobotAtlas
01-02-2011, 11:03 AM
What type of joystick do you want to use?
As far as example of code goes, there's commander.py on ArbotiX website. It should get you started.

DresnerRobotics
01-02-2011, 11:29 AM
He's using a Commander and Arbotix, so I assume he's talking about the Commander's joysticks providing input to the Arbotix via xbee connection/Commander protocol. Shouldn't be any Python involved as this is Commander >> Arbotix interaction.

This code could be a bit more compressed, but I feel it self-documents pretty well. This controls an Arbotix based pan/tilt using a single joystick from a Commander.


#include <Commander.h>
#include <ax12.h>
#include <BioloidController.h>

BioloidController bioloid = BioloidController(1000000);
Commander command = Commander();

int rjoypan;
int rjoytilt;
int panservo;
int tiltservo;

void setup()
{

// setup serial
Serial.begin(38400);
SetPosition(1,512);
SetPosition(2,512);
delay(3000);
}

void loop()
{
if(command.ReadMsgs() > 0)
{
rjoypan = command.lookH;
panservo = map(rjoypan, -128, 128, 0, 1024);
rjoytilt = command.lookV;
tiltservo = map(rjoytilt, -128, 128, 0, 1024);
SetPosition(1,panservo);
SetPosition(2,tiltservo);
}
}

Buell24
01-02-2011, 11:51 PM
Yes, exactly that I was searching for! What exactly does the instruction map? Is there any documentation about?
thanks a lot for your help!

lnxfergy
01-03-2011, 09:22 AM
Yes, exactly that I was searching for! What exactly does the instruction map? Is there any documentation about?
thanks a lot for your help!

http://www.arduino.cc/en/Reference/Map

-Fergs

Buell24
01-03-2011, 12:45 PM
Thank you for the documentation.
I saw, that the instruction “map” is only to convert the data of the joystick. But that isn’t what I want to do.
I’d like to control the speed of a servo using the value of the joystick. So that I can move the servo very fast and also very slow and precise. The value of the joystick should not be the absolute position.
I think of a use like this: I want to reach a target with a pan/tilt cannon. The target is far away (in degrees). So I can make a full-scale deflection with the joystick to get very fast in the near of the target. Then I can go back with the joystick to move very slowly and precise over the target.
Is something like that possible?

gdubb2
01-03-2011, 01:01 PM
I don't know anything about these servos, but with hobby servos, it would be as simple as using the second joystick on the Commander, convert the position reading to a speed setting for the servo, and send it to the servo. I do something similar with my mech, but use a button to determine which speed setting it transmitted to the servo. The pan/tilt settings just work normally but at different speeds.

Gary

DresnerRobotics
01-03-2011, 01:29 PM
Sounds like you're looking for some code that doesn't directly control the movement and won't auto-center.

Try replacing your main loop with something like this:


void loop()
{
if(command.ReadMsgs() > 0)
{
panservo += - command.lookH/20;
tiltservo -= - command.lookV/30;
SetPosition(1,panservo);
SetPosition(2,tiltservo);
}
}

This will move the servo more quickly the further away from the center it is.

Buell24
01-04-2011, 02:15 AM
Yes, that I was looking for. Can you tell me how the method SetPosition calculates the speed? Is there an interpolating routine behind? Is there no way to directly set a current speed to the servos?

lnxfergy
01-04-2011, 12:47 PM
Yes, that I was looking for. Can you tell me how the method SetPosition calculates the speed? Is there an interpolating routine behind? Is there no way to directly set a current speed to the servos?

There is no speed control in SetPosition -- the servo will move as fast as possible to the desired location. By calling SetPosition over and over again with small incremental changes, we can approximate moving at a slower speed.

There is a higher level interpolation system built into the BioloidController library -- using poses, see the ArbotiX wiki.

There is also speed control on the AX-12s -- but you sacrifice torque to move at slower speeds. You'll have to do a "ax12SetRegister" command, see the ArbotiX wiki + AX12 datasheet.

-Fergs