Go to Post Thank you from the bottom of our IFI controllers, The Robonauts. - Natchez [more]
Home
Go Back   Chief Delphi > Technical > Motors
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-04-2016, 15:05
Arrow93 Arrow93 is offline
Registered User
no team
 
Join Date: Apr 2016
Location: Canada
Posts: 2
Arrow93 is an unknown quantity at this point
Arduino + Jaguar Speed Controller + CIM Motor

I have connected a CIM motor to a Jaguar speed controller, powered by 12V battery. The jaguar is connected to an Arduino UNO via the signal and ground. Also, I have two switches connected to the Arduino, for forward and reverse of the motor.

In the code, for speed of the motor, I have set 90 as the mid point and 100 for forward and 80 for reverse. When I push the reverse button, the motor runs smoothly in the reverse direction at the set speed. However, the problem is, when I press the forward button, the motor runs seemingly slower in the forward direction than the set speed. My logic here was, if I have set speeds in forward and reverse at +/- 10 from the mid-point, the motor should run at the same speed in the forward and reverse direction, but this is not happening.

I am pasting my code below. Any help would be much appreciated. Thank you!


Code:
#include <Servo.h> 

int forwardPin = 2;
int reversePin = 4;
int motorPin = 10;
int fwdReading = 0;
int revReading = 0;

Servo myservo;

void setup() 
{ 
  TCCR1B = TCCR1B & 0b11111000 | 0x04; // PWM Freq. at 122Hz
  
  pinMode (forwardPin, INPUT);
  pinMode (reversePin, INPUT);
  myservo.attach(motorPin);
  myservo.write(90);  // set servo to mid-point
} 

void loop() 
{
  fwdReading = digitalRead(forwardPin);
  revReading = digitalRead(reversePin);
  
  if (fwdReading == HIGH)
  {
    myservo.write(100); // forward
  }  
   else if (revReading == HIGH)
  {
    myservo.write(80); // reverse
  }
  else
  myservo.write(90); // neutral
}
Reply With Quote
  #2   Spotlight this post!  
Unread 05-04-2016, 15:38
tr6scott's Avatar
tr6scott tr6scott is online now
Um, I smell Motor!
AKA: Scott McBride
FRC #2137 (TORC)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2005
Location: Oxford, MI
Posts: 507
tr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond repute
Re: Arduino + Jaguar Speed Controller + CIM Motor

Here is my hacked code for our test box, that drives two jags, for our test box. It has two pots that are used for speed controls, to drive the servo output, there are two pots and two jags on our test box.

I did this many years ago, it uses the map command, it works. Hopefully it helps. It has been a long time since I played with it, but we use it everyday for prototyping.

The jag connected to myservo runs forward and reverse, the jag connected to the myservo1 only runs forward. Look at Map command arguments, 90 to 180.



Code:
// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
Servo myservo1;  // create servo object to control a servo 
 
int potpin = 0;  // pot in is 13 pwm analog pin used to connect the potentiometer
int potpin1 = 1;  // analog pin used to connect the potentiometerint val;    // variable to read the value from the analog pin 
int val =0;
int val1=0;
void setup() 
{ 
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
 myservo1.attach(10);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) //
  val1 = analogRead(potpin1);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  val1 = map(val1, 0, 1023, 90, 179);     // scale it to use it with the servo (value between 0 and 180) 
   myservo.write(val);                  // pwm 13 sets the servo position according to the scaled value 
   myservo1.write(val1);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
}
__________________
The sooner we get behind schedule, the more time we have to catch up.

Reply With Quote
  #3   Spotlight this post!  
Unread 05-04-2016, 15:44
tr6scott's Avatar
tr6scott tr6scott is online now
Um, I smell Motor!
AKA: Scott McBride
FRC #2137 (TORC)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2005
Location: Oxford, MI
Posts: 507
tr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond repute
Re: Arduino + Jaguar Speed Controller + CIM Motor

May also need to calibrate Jag and see if you get the expected results. to calibrate you will need full forward and full reverse speeds.

-----------------------

To calibrate the servo-style PWM input for a specific range, connect a PWM source, then:
1. Hold down the USER switch with a straightened paper clip for 5 seconds.
2. The LED flashes Red and Green to indicate Calibration mode.
3. Instruct the controller to send a full-forward signal for one or more seconds.
4. Instruct the controller to send a full-reverse signal for one or more seconds.
5. The LED flashes Green and Yellow quickly to indicate a successful calibration.
The Jaguar samples these signals and centers the speed range and neutral position between these limits. A
calibration failure signals if an out-of-range signal is detected. This condition is indicated by flashing the LED
Red and Yellow

http://content.vexrobotics.com/docs/...artedGuide.pdf
__________________
The sooner we get behind schedule, the more time we have to catch up.


Last edited by tr6scott : 05-04-2016 at 15:54. Reason: added info.
Reply With Quote
  #4   Spotlight this post!  
Unread 05-04-2016, 16:02
Arrow93 Arrow93 is offline
Registered User
no team
 
Join Date: Apr 2016
Location: Canada
Posts: 2
Arrow93 is an unknown quantity at this point
Re: Arduino + Jaguar Speed Controller + CIM Motor

@tr6scott Hey thanks a lot! I will edit the code tonight and check if the map command works.
I have tried to calibrate it several times from 0 to 180 and works perfectly but when I have it from 80 to 100 with 90 as midpoint, the forward speed seems slower compared to reverse speed
Reply With Quote
  #5   Spotlight this post!  
Unread 05-04-2016, 16:33
tr6scott's Avatar
tr6scott tr6scott is online now
Um, I smell Motor!
AKA: Scott McBride
FRC #2137 (TORC)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2005
Location: Oxford, MI
Posts: 507
tr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond reputetr6scott has a reputation beyond repute
Re: Arduino + Jaguar Speed Controller + CIM Motor

It's coming back to me, what you have looks fine, I'd be tempted to stick with it, and add the delay to the loop... that maybe the issue. From the map command it should be 0 to 179, not sure what happens when you tell it 180... maybe add the delay, set it up 0 to 179, then calibrate the jag, and then see if it behaves.
__________________
The sooner we get behind schedule, the more time we have to catch up.


Last edited by tr6scott : 05-04-2016 at 16:35. Reason: another thought.
Reply With Quote
  #6   Spotlight this post!  
Unread 05-04-2016, 20:35
teslalab2's Avatar
teslalab2 teslalab2 is offline
RogueBotix LLC
VRC #8091
Team Role: Mentor
 
Join Date: Feb 2015
Rookie Year: 2014
Location: Austin MN
Posts: 109
teslalab2 will become famous soon enoughteslalab2 will become famous soon enough
Re: Arduino + Jaguar Speed Controller + CIM Motor

I wrote a library for this

https://sourceforge.net/projects/ard...?source=navbar

its makes running motor controllers really easy.
__________________
I need a jaguar development board for reprogramming a jaguars bootloader. if you have one that you want to sell, pm me. thanks

Run you CanJaguars on arduino with ArduRIO, you can also easily control Talons, Victors,Jaguars and Sparks on PWM. https://sourceforge.net/projects/ardurio/
Reply With Quote
  #7   Spotlight this post!  
Unread 14-04-2016, 10:33
NickLD3753's Avatar
NickLD3753 NickLD3753 is offline
Registered User
FRC #3753 (BulahBots)
Team Role: Programmer
 
Join Date: Apr 2016
Rookie Year: 2015
Location: Louisiana
Posts: 1
NickLD3753 is an unknown quantity at this point
Re: Arduino + Jaguar Speed Controller + CIM Motor

Hi, I think what your issue is might be with the default pulse-width of the signal coming from the Servo library.

Some manufactures decide to vary their input range from the standard timings. Also, most RC servos (what the Library was made for) have a different range from what I have seen FRC Controllers use most of the time.

I did a quick look for the Jaguar Datasheet and found this:
http://content.vexrobotics.com/docs/...t_20130220.pdf

This is what the Datasheet says about the input range:

Minimum pulse width 0.67 ms
Neutral pulse width 1.5 ms
Maximum pulse width 2.33 ms

All We need to do now is convert the ms to us:

Minimum pulse width 670 us
Neutral pulse width 1500 us
Maximum pulse width 2330 us


Now the great thing about the servo library is the ability to skip the scaling of the normal RC servo range and just input the raw us timing values.

Code:
myservo.writeMicroseconds(UsTiming);
After that It should be pretty easy to map the values accordingly.

I hope that solves your issue!
Reply With Quote
  #8   Spotlight this post!  
Unread 14-04-2016, 11:16
Unsung FIRST Hero
Al Skierkiewicz Al Skierkiewicz is offline
Broadcast Eng/Chief Robot Inspector
AKA: Big Al WFFA 2005
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1996
Location: Wheeling, IL
Posts: 10,766
Al Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond repute
Re: Arduino + Jaguar Speed Controller + CIM Motor

Please don't forget that the CIM motor has a brush bias that is optimized for one direction over the other. While it is slight, there are production variances that may make individual motors respond differently. Other motors are known to have greater bias differences.
__________________
Good Luck All. Learn something new, everyday!
Al
WB9UVJ
www.wildstang.org
________________________
Storming the Tower since 1996.
Reply With Quote
  #9   Spotlight this post!  
Unread 14-04-2016, 16:00
Michael Hill's Avatar
Michael Hill Michael Hill is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Mentor
 
Join Date: Jul 2004
Rookie Year: 2003
Location: Dayton, OH
Posts: 1,567
Michael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond reputeMichael Hill has a reputation beyond repute
Re: Arduino + Jaguar Speed Controller + CIM Motor

Quote:
Originally Posted by Al Skierkiewicz View Post
Please don't forget that the CIM motor has a brush bias that is optimized for one direction over the other. While it is slight, there are production variances that may make individual motors respond differently. Other motors are known to have greater bias differences.
Could you tune this by loosening the bolts, and rotating the black section that houses the permanent magnets (Not saying this would/should be legal on an FRC robot, just technically possible). There are tick marks on each of the sections so you could potentially reliably clock the magnets in relation to the brushes.
Reply With Quote
Reply


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 22:49.

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