PDA

View Full Version : [Question(s)] Arbotix based rover VivianII



darkback2
06-08-2012, 03:21 PM
A student of mine decided to revive vivian as a special project. We are switching from a paintball gun to a laser because we are in a school and guns in school = expulsion. The plan is to mount a trendnet on the front mech warfare style and use an arbotix as the main controller board. We are using a vantec dual electronic speed controller controlling the original 4 denso motors.

Here is where we ran into trouble. The vantec dual sided ESP uses 2 pwm signals mapped to servo positions. The ESP takes in servo positions corresponding from 0 to 180 degrees. One signal controlls the throttle, and the other one controls the direction. The vantec does the mixing for you. We have connected the throttle input to servoA on the arbotix and the stearing input to servoB. After a call to Andrew we learned that servoA output corresponds to digital out 12, and ServoB corresponds to digital out 13.
40394040
The code is meant to move the pan and tilt AX-12 servos when we move the look joystick on the commander. The throttle and stearing is meant to be linked to the position of the walk stick. Moving the stick should directly correspond to the pwm output on the servoA and B outputs.


// pd4 is servo B pd 5 is servo A pd4 d12 and pd5 is d13
#include <ax12.h>
#include <BioloidController.h>
#include <Commander.h>
#include <Servo.h>
BioloidController bioloid = BioloidController(1000000);
Commander command = Commander();
int mode;
int panh;
int panadd;
int pany;
int panyadd;
int tspos;
int sspos;
Servo TServo;
Servo SServo;
void setup(){

panh = 512;
panadd = 1;
pany = 512;
panyadd = 1;
tspos = 90;
sspos = 90;
TServo.attach(12);
SServo.attach(13);

//open the serial port
command.begin(38400);
// stand up slowly
delay(100); // recommended pause
bioloid.readPose();
bioloid.interpolateSetup(500);
while(bioloid.interpolating > 0){
bioloid.interpolateStep();
delay(3);
}
}
void loop(){
if(command.ReadMsgs() > 0){ // check for new messages
digitalWrite(0,HIGH-digitalRead(0)); // toggle LED so we know johnny5 is alive
if(bioloid.playing == 0)
{ // only process if we aren't currently doing a sequence
if (command.lookH > 25){
panh += (2 * panadd);
SetPosition(1,(panh));
}else if (command.lookH < -25){
panh -= (2 * panadd);
SetPosition(1,(panh));
}else if (command.lookV > 25){
pany += (2 * panyadd);
SetPosition(2,(pany));
}else if (command.lookV < -25){
pany -= (2 * panyadd);
SetPosition(2,(pany));
}else if (command.walkH > 0){
SServo.write(((command.walkH+125)/2.5) * 1.8);
}else if (command.walkH < 0){
SServo.write(((command.walkH+125)/2.5) * 1.8);
}else if (command.walkV > 0){
TServo.write(((command.walkV+125)/2.5) * 1.8);
}else if (command.walkV < 0 ){
TServo.write(((command.walkV+125)/2.5) * 1.8);
}
}
}// end else

if(bioloid.playing > 0) {
bioloid.play(); // continue sequence
}
} //end loop



Needless to say this almost works...Currently the wheels turn, but not in the direction that we want them to. This might have to do with a wiring issue via the ESPs and thier connection to the motors, but the movement seams to have little to do with the movement of the joystick.

Any help would be greatly appreciated.

DB and his student.

lnxfergy
06-09-2012, 07:37 AM
The issue is probably that big if/else block -- it should actually be several blocks:



void loop(){
if(command.ReadMsgs() > 0){ // check for new messages
digitalWrite(0,HIGH-digitalRead(0)); // toggle LED so we know johnny5 is alive
if(bioloid.playing == 0)
{ // only process if we aren't currently doing a sequence
if (command.lookH > 25){
panh += (2 * panadd);
SetPosition(1,(panh));
}else if (command.lookH < -25){
panh -= (2 * panadd);
SetPosition(1,(panh));
}

// processing a different command -- needs to be a new if/else block:
if (command.lookV > 25){
pany += (2 * panyadd);
SetPosition(2,(pany));
}else if (command.lookV < -25){
pany -= (2 * panyadd);
SetPosition(2,(pany));
}

// processing a different command -- needs to be a new if/else block:
if (command.walkH > 0){
SServo.write(((command.walkH+125)/2.5) * 1.8);
}else if (command.walkH < 0){
SServo.write(((command.walkH+125)/2.5) * 1.8);
}

// and one last block
if (command.walkV > 0){
TServo.write(((command.walkV+125)/2.5) * 1.8);
}else if (command.walkV < 0 ){
TServo.write(((command.walkV+125)/2.5) * 1.8);
}
}
}// end bew message else

if(bioloid.playing > 0) {
bioloid.play(); // continue sequence
}
} //end loop

darkback2
06-14-2012, 10:23 AM
So here is where we currently are. The rover wasn't working properly when we tried to use math to map the position of the walk joystick to the throttle and steering values. The results were really strange and the behaviors were not what we would have expected. We decided to do an experiment where we basically used code to turn the joysticks into buttons. So moving the joystick past a certain threshold turns the motors on for a set amount of time in the desired direction. Here the code seams to work, but only for a few times. After a few times of steering or moving the robot stops responding to the walk joystick, but continues to execute the pantilt code on the dynamixel servos. Pressing the reset button on the arbotix makes everything work again.

I'm thinking that there is something wrong with the code resulting in the arbotix getting stuck in some way so that it can no longer accept commands from the walk joystick.

In anycase here is the code we are using.


// pd4 is servo B pd 5 is servo A pd4 d12 and pd5 is d13
#include <ax12.h>
#include <BioloidController.h>
#include <Commander.h>
#include <Servo.h>
BioloidController bioloid = BioloidController(1000000);
Commander command = Commander();
//here we are creating variabls (places where we can store numbers
int panh; //the value of the horizontal pan servo position
int panadd; //the value being added to the horizontal pan servo position
int pany; //the value of the verticle tilt servo position
int panyadd; //the value being added to the verticle tilt servo position
int tspos; //the position of the throttle value
int sspos; //the position of the steering value
Servo TServo; //this tells the arbotix that it has a throttle servo
Servo SServo; //this tells the arbotix that it has a stearing servo
//the setup loop is where we tell the arbotix what is what about the robot
void setup(){

panh = 348; //set the horizontal pan servo to its midpoint
panadd = 1; //set the value being added to the servo position to 1
pany = 512; //set the virtical tilt servo to its midpoint
panyadd = 1; //set the value being added to teh servo position to 1
tspos = 90; //sets the throttle to stopped.
sspos = 90; //sets the steering to neutral
TServo.attach(12); //tells the arbotix that the throttle output is on pin 12 (servo A)
SServo.attach(13); //tells teh arbotix that the steering output is on pin 13 (servo B)

//open the serial port
command.begin(38400);
//you don't really need this next part...
// stand up slowly
delay(100); // recommended pause
bioloid.readPose();
bioloid.interpolateSetup(500);
while(bioloid.interpolating > 0){
bioloid.interpolateStep();
delay(3);
}
}
void loop(){
if(command.ReadMsgs() > 0){ // check for new messages
digitalWrite(0,HIGH-digitalRead(0)); // toggle LED so we know johnny5 is alive
if(bioloid.playing == 0)
{ // only process if we aren't currently doing a sequence

// If I move the right joystick move the dynamixel servos panning the gun
if (command.lookH > 40){
panh += (5 * panadd);
SetPosition(1,(panh));
}else if (command.lookH < -40){
panh -= (5 * panadd);
SetPosition(1,(panh));
}
// processing a different command -- needs to be a new if/else block:
//if I move the right joystick up and down move the dynamixel tilt servo aiming up and down
if (command.lookV > 25){
pany += (3 * panyadd);
SetPosition(2,(pany));
}else if (command.lookV < -25){
pany -= (3 * panyadd);
SetPosition(2,(pany));
}
// processing a different command -- needs to be a new if/else block:
if (command.walkH > 40){
SServo.write(135);
TServo.write(90);
delay (25);
SServo.write(90);
TServo.write(90);
}else if (command.walkH < -40){
SServo.write(45);
TServo.write(90);
delay (25);
SServo.write(90);
TServo.write(90);

}
// and one last block
if (command.walkV > 40){
TServo.write(135);
SServo.write(90);
delay (100);
TServo.write(90);
SServo.write(90);
}else if (command.walkV < -40 ){
TServo.write(45);
SServo.write(90);
delay (100);
TServo.write(90);
SServo.write(90);
}
}
}// end bew message else
if(bioloid.playing > 0) {
bioloid.play(); // continue sequence
}
} //end loop


Any help would be greatly appreciated.

DB