arduino victor 884 and a cim

Hello everyone, my goal here is to find a simplified code to get an arduino to run a spike with a cim

so I have looked around for a couple days and sorry but it all seems to come up null. i have seen a lot about servo libraries and endless lines of code just to turn one motor in either direction, here is the ultimate goal i have in mind: hook directly into the potentiometers on my attack 3, and use it to control the speed and direction of 2 cims for a basic drive train. for now i would settle just to see being able to turn it one direction or the other with the code.

So i have the ground wire hooked to ground, the wire on the right hooked to pin 10, I have tried analog and digital but neither give me an easy way to control it. I have the victor itself hooked up to the std. 12v battery through a 40 amp breaker to be safe. I would imagine that the code necessary to turn it either way continuously should be encomppased in less than 6 lines and i think the issue is with the delay, any suggestions?

Thanks,
Nick

http://arduino.cc/en/Reference/ServoAttach

I was able to use this for a project last year. It required some finagling, as I could not just use 0-255 and had to figure out what values corresponded to full reverse, full forward, and off. This was for a very light duty application and didn’t involve continuous rotation, so YMMV.

I can confirm Cory’s suggestion. The PWM signal to control a Victor or a Jag is identical as that used to position a Servo. So, just use that library and convert angle to speed. ie. 0 deg = full reverse, 90 deg = stopped, 180 deg = full forward. The exact values will more than likely be a bit different from this, but they are close enough to get you going.

why am i so incompetent at stuff like this, i just dont see how it all adds up, could you post a few lines of example code? just enough to make it run in 1 direction and i can probably figure it out.

Thanks,
Nick

Here is the code from the project I referenced:

#include <Servo.h>

Servo myservo1;

Servo myservo2;

void setup()

{

pinMode(10, OUTPUT); //motor

pinMode(11, OUTPUT); //solenoid

pinMode(12, INPUT); //Switch 0

pinMode(8,INPUT);//Switch 1

digitalWrite(12, HIGH); // turn on pullup resistor

digitalWrite(8,HIGH); //turn on pullup resistor

myservo1.attach(10); //motor

myservo2.attach(11); //solenoid

Serial.begin(9600);

}

void loop()

{

int button_0=digitalRead(12);

int button_1=digitalRead(8);

while ((button_0==0) && (analogRead(A0)!=0)) //while button 0 is pressed and A0 is not equal to 0

{

myservo1.write(0); //close door

}

while ((button_1==0) && (analogRead(A1)!=0)) //while button 1 is pressed and A1 is not equal to 0

{

myservo2.write(180); //activate solenoid

myservo1.write(112); //open door

}

myservo1.write(92); //turn off motor

myservo2.write(92); //turn off solenoid

}

pullup resistors and solenoids, I read its best to use servo coding even for a cim, but i just cant say i understand how these relate. Solenoid = victor? what would the pullup resistor do (im reading something about returning it to a state if no input is read, maybe to read that the joystick is let off?)? If this is what works for a victor and cim (i guess it doesnt matter what type of motor right?) then maybe it would be best just to look at your wireing diagram, or if you want i can create one for what i have if you would like.

Thanks,
Nick

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.:wink:
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):ahh:

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.

That code was to operate a motor and a solenoid. The reason it might look weird is that I ended up having to use a victor to run the solenoid. As @#@#$@# backwards as that sounds it was something like 3 AM when I was finishing that up and just couldn’t get the spike to do what I wanted it to, so I switched to a victor so I wouldn’t have to mess around making the spike work.

The pullup resistor part had to do with limit switches.

I can see why you might be confused. Both a Servo and the Victor/Jaguar/Talon speed controllers are controlled by a “PWM” signal. PWM stands for Pulse Width Modulation. To be more specific, they use what is commonly called “Hobby PWM”.

The easiest way to describe the signal is a pulse train. The frequency of the pulses is usually around 50Hz. Although, some devices can handle frequencies up to 200Hz.

The important part is the width of the pulses. A standard “Hobby PWM” signal has a duration varying from 1ms to 2ms. 1ms corresponds 0 deg. on a servo or full reverse on a motor controller. 1.5ms is 90 deg on a servo and neutral on a motor controller. Lastly, 2ms is 180 deg on the servo and full forward on the motor controller. The varying width of the pulse is where the “Modulation” in PWM comes from. By modulating the pulse width, you control the speed of the motor or position of the servo.
These values are fairly generic, the exact values may be slightly different from these.

So, as you can see, the motor controller can be run by a “Servo Library” because it is the signal coming out that makes the controller drive the motor at the desired speed and direction, and not the fact that it is a “Servo Library”.

^cut that down for quoteing
ill be looking through this soon but not tonight, it looks promising though so thank you, i was scared people werent understanding my goals.

to answer your question, i took apart the attack 3, where the usb comes into the housing there is a red and a black wire, and a few more but dont worry about those, so i ran the red to the 5v supply on the arduino and the black to the ground. then on the right side of the stick there is a 5 pin connector. Red, yellow, green, orange, and blue. The red and blue are power, the yellow and green give direct analog output though, so does the orange but that is for the throttle control on the back of the joystick. So since I gave the entire joystick power through the wires on the usb, I can really get all the buttons to work, but I connected wires to the green and yellow wires and was able to get an analog read on the arduino

https://photos-5.dropbox.com/t/0/AADHGV82LoPleMVFKzM6iiVNWtxLR_UW0AtnZcaan2iGfA/12/128655095/jpeg/32x32/3/_/1/2/20130313_215614.jpg/DNNm-sMqdt6PMQbdcKPxOeTo2jImt3IM9Vz-3zusdiI?size=1280x960

Your link is broken or requires a log in.


that should be better, sorry

not a great way of doing things, but in my case i would like to bypass the use of a computer so its neccessary from what i can reason





So something like this does have to oscilate right? Its not like i send it a 2ms pulse and it just runs full throttle until i tell it otherwise, as soon as i stop giving this 2ms pulse every so often it stops running?

correct. You need to sens a new 2ms pulse very cycle. A cycle in typical hooby servos (99% of PWM devices) use a 20ms cycle. Some modules in FRC use faster times like 10 or even 5ms.

The original post here requests information on controlling a CIM with a Spike, not a proportional motor controller. If that is still the case, then you do not want to output PWM signals at all. In fact, you do not even want to wire the cable the same way as if it was a PWM output. What you will need is two digital outputs, one connected to each of the two non-ground pins of a three pin PWM cable.

In this case, the fact that a three pin PWM cable is used for the connection to a Spike can be a source of confusion. The signals are not PWM at all. They are just simple logic signals, one for full forward, and one for full reverse. While connecting a spike to PWM signals may make it do something, it will not act properly. It will most likely either run all the time fully on in one direction only, or run in a jerky maner. A spike simply is not designed to operate with PWM signals

If you are in fact still trying to make the Arduino control a Spike relay and not a Jaguar, Talon, or Victor motor controller than do not use the servo library at all. Just connect TWO digital outputs pins rather than one and send them simple high and low output commands. On the spike, the center pin that would be power, if the cable was going to a servo, is actually the other control pin. Change the wiring and use digital output commands and you should have better luck controlling a Spike.

Tom

Finally found time to work on this again, on the contrary I am using a victor, sorry if i said spike somewhere.
just wired it up and copied in the code and it works as it is programmed for, tankdrive, im going to see about modifying it a bit for arcade, ill post results soon

so i have worked through it and i think i have AN answer, but definatly not THE answer. I see a benefit to tankdrive, this deadzone is going to make turning horrendous

#include <Servo.h>

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

int JoyRL = A0; //value of Y axis on left joystick
int JoyFB = A1; //value of Y asis on RIght joystick

int FBval = 90; // variable to store the read FBvalue
int RLval = 90; // variable to store the read RLvalue

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

void loop() {
FBval = analogRead(JoyFB);
FBval = map(FBval, 0, 1023, 0, 180)+10; //joystick miscalibration brought me here
RLval = analogRead(JoyRL);
RLval = map(RLval, 0, 1023, 180, 0);
delay(100);
analogRead(FBval);
Serial.println(FBval);

if(FBval < 85 || FBval > 95) { //Deadband
forward();
} else if(RLval < 85 || RLval > 95) { //Deadband
side();
}else{
RightMotor.write(90);
LeftMotor.write(90);
}

}
void forward() {
RightMotor.write(FBval);
LeftMotor.write(FBval);
}

void side() {
RightMotor.write(RLval);
LeftMotor.write(RLval);
}

now my jerry rigged motor inclusive wiring system just fell apart for the like millionth time so i cant know for sure, but what i saw on the victor is that it drops out a lot unless the joystick is in the middle, if the light is blinking up can i forget about seeing movement in the cim? if so i can almost guarentee that the problem is in the if/then/else statements im using, any suggestions on how to make it so those work together rather than against eachother?