View Single Post
  #7   Spotlight this post!  
Unread 13-03-2013, 20:14
thinker&planner thinker&planner is offline
Registered User
AKA: CAAAAAD
no team
Team Role: Mechanical
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Tallahassee, FL
Posts: 115
thinker&planner is a splendid one to beholdthinker&planner is a splendid one to beholdthinker&planner is a splendid one to beholdthinker&planner is a splendid one to beholdthinker&planner is a splendid one to beholdthinker&planner is a splendid one to beholdthinker&planner is a splendid one to behold
Thumbs up Re: arduino victor 884 and a cim

I recently had to do a bunch or research on this topic, so here's my code. I read joysticks as pots through analog pins, so it might be a little different. I would love to know how you end up getting raw pot data from attack 3 because I looked for a bit but couldn't find out how.
Also, I set this up as tank drive with two joysticks. The important part is treating the Victor as a "servo" because it uses "RC" PWM frequencies, which are not at all the same as Arduino's analogWrite function.

#include <Servo.h>

Servo LeftMotor; //not really a servo!
Servo RightMotor; //not really a servo!



int JoyLY = A0; //value of Y axis on left joystick
int JoyRY= A1; //value of Y asis on RIght joystick

int LYval = 90; // variable to store the read LYvalue
int RYval = 90; // variable to store the read RYvalue


void setup() {
LeftMotor.attach(9);
RightMotor.attach(10);
}



void loop() {

LYval = analogRead(JoyLY); // read the left Y input
LYval = map(LYval, 0, 1023, 0, 180); //converts to "degrees"
RYval = analogRead(JoyRY); // read the right Y input
RYval = map(RYval, 0, 1023, 180, 0); //This statement is switched because one of the joysticks was inverted. (Just so you know how to invert it)

if(LYval < 87 || LYval > 93) { //Deadband
left();
}
else{
LeftMotor.write(90);
}

if(RYval < 87 || RYval > 93) { //Deadband
right();
}
else{
RightMotor.write(90);
}

}


void left() {
LeftMotor.write(LYval); // analogRead values go from 0 to 1023 (Only using 512-1023), analogWrite values from 0 to 255
}

void right() {
RightMotor.write(RYval);
}


EDIT:
So that you know, the Victor will treat a "servo angle" from 91-180 as forward speeds and values from 89-0 as reverse speeds.

Last edited by thinker&planner : 13-03-2013 at 20:17.