Go to Post The world has never seen a group of people who have taken such interest and delight in being rickrolled. - StevenB [more]
Home
Go Back   Chief Delphi > Technical > Electrical
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-03-2013, 23:34
Crawler Crawler is offline
Registered User
FRC #3749
 
Join Date: Jan 2012
Location: San Diego
Posts: 19
Crawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the rough
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
  #2   Spotlight this post!  
Unread 13-03-2013, 00:19
Cory's Avatar
Cory Cory is offline
Registered User
AKA: Cory McBride
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: May 2002
Rookie Year: 2001
Location: Redwood City, CA
Posts: 6,824
Cory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond repute
Send a message via AIM to Cory
Re: arduino victor 884 and a cim

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.
__________________
2001-2004: Team 100
2006-Present: Team 254
  #3   Spotlight this post!  
Unread 13-03-2013, 00:24
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,384
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: arduino victor 884 and a cim

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.
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
  #4   Spotlight this post!  
Unread 13-03-2013, 01:38
Crawler Crawler is offline
Registered User
FRC #3749
 
Join Date: Jan 2012
Location: San Diego
Posts: 19
Crawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the rough
Re: arduino victor 884 and a cim

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
  #5   Spotlight this post!  
Unread 13-03-2013, 01:56
Cory's Avatar
Cory Cory is offline
Registered User
AKA: Cory McBride
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: May 2002
Rookie Year: 2001
Location: Redwood City, CA
Posts: 6,824
Cory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond repute
Send a message via AIM to Cory
Re: arduino victor 884 and a cim

Quote:
Originally Posted by Crawler View Post
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

}
__________________
2001-2004: Team 100
2006-Present: Team 254
  #6   Spotlight this post!  
Unread 13-03-2013, 18:34
Crawler Crawler is offline
Registered User
FRC #3749
 
Join Date: Jan 2012
Location: San Diego
Posts: 19
Crawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the rough
Re: arduino victor 884 and a cim

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
  #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.
  #8   Spotlight this post!  
Unread 13-03-2013, 22:39
Cory's Avatar
Cory Cory is offline
Registered User
AKA: Cory McBride
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: May 2002
Rookie Year: 2001
Location: Redwood City, CA
Posts: 6,824
Cory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond reputeCory has a reputation beyond repute
Send a message via AIM to Cory
Re: arduino victor 884 and a cim

Quote:
Originally Posted by Crawler View Post
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
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.
__________________
2001-2004: Team 100
2006-Present: Team 254
  #9   Spotlight this post!  
Unread 14-03-2013, 00:47
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,384
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: arduino victor 884 and a cim

Quote:
Originally Posted by Crawler View Post
... I read its best to use servo coding even for a cim, but i just cant say i understand how these relate. ....

Thanks,
Nick
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".
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
  #10   Spotlight this post!  
Unread 14-03-2013, 00:54
Crawler Crawler is offline
Registered User
FRC #3749
 
Join Date: Jan 2012
Location: San Diego
Posts: 19
Crawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the rough
Re: arduino victor 884 and a cim

Quote:
Originally Posted by thinker&planner View Post
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.
^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/AAD...?size=1280x960

Last edited by Crawler : 14-03-2013 at 01:01. Reason: adding a picture of the joystick
  #11   Spotlight this post!  
Unread 14-03-2013, 01:09
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,384
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: arduino victor 884 and a cim

Quote:
Originally Posted by Crawler View Post
Your link is broken or requires a log in.
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
  #12   Spotlight this post!  
Unread 14-03-2013, 01:12
Crawler Crawler is offline
Registered User
FRC #3749
 
Join Date: Jan 2012
Location: San Diego
Posts: 19
Crawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the rough
Re: arduino victor 884 and a cim

Click image for larger version

Name:	DNNm-sMqdt6PMQbdcKPxOeTo2jImt3IM9Vz-3zusdiI.jpg
Views:	50
Size:	194.5 KB
ID:	14343
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
  #13   Spotlight this post!  
Unread 14-03-2013, 01:25
Crawler Crawler is offline
Registered User
FRC #3749
 
Join Date: Jan 2012
Location: San Diego
Posts: 19
Crawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the roughCrawler is a jewel in the rough
Re: arduino victor 884 and a cim

Quote:
Originally Posted by billbo911 View Post
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.
.
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?
  #14   Spotlight this post!  
Unread 14-03-2013, 08:20
engunneer's Avatar
engunneer engunneer is offline
Alumni turned Mentor
AKA: Branden Gunn
FRC #4761
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1996
Location: Reading, MA
Posts: 876
engunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond repute
Re: arduino victor 884 and a cim

Quote:
Originally Posted by Crawler View Post
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.
__________________
Student FRC23 (1996-1999), Mentor FRC246 (2000), Mentor FRC1318 (2007-2009), Mentor FRC93 (2011), Mentor FRC2151 (2012), Mentor FRC23 (2013), Mentor FRC4761 (2014-2017)
1998 - National Chairman's Award and Woodie Flowers Award (FRC23, Mike Bastoni ) | 2007 - PNW SF (488, 1595) | 2008 - Oregon RCA - Seattle #2 Seed, SF (488, 1696) | 2009 - Oregon #1 Seed, Winners (1983, 2635) - Seattle SF (945, 2865) - Galileo #2 Seed, SF (973, 25) | 2012 Midwest F (111, 71) | 2014 RIDE Winners (78, 125), Inspector - NEU #24, QF (3479, 3958) - NECMP #35 | 2015 Reading #11, SF (1058, 190), Inspector - RIDE #17, QF(4055, 5494), Inspector - NECMP #57 | 2016 Reading #4, SF (133, 4474), DCA, Inspector - Ride #22, SF (1735, 2067), Creativity, Inspector - NECMP #48, RCA - Archimedes
  #15   Spotlight this post!  
Unread 15-03-2013, 11:56
tsaksa's Avatar
tsaksa tsaksa is offline
Registered User
FRC #0997 (CHS Robotics)
Team Role: Mentor
 
Join Date: Jul 2011
Rookie Year: 2011
Location: Corvallis Oregon
Posts: 203
tsaksa has a reputation beyond reputetsaksa has a reputation beyond reputetsaksa has a reputation beyond reputetsaksa has a reputation beyond reputetsaksa has a reputation beyond reputetsaksa has a reputation beyond reputetsaksa has a reputation beyond reputetsaksa has a reputation beyond reputetsaksa has a reputation beyond reputetsaksa has a reputation beyond reputetsaksa has a reputation beyond repute
Re: arduino victor 884 and a cim

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
__________________
This is the zeroth day of the rest of your life.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 20:14.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi