Go to Post Winning is an outcome, not the whole point. - StephLee [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
  #16   Spotlight this post!  
Unread 28-05-2012, 00:47
JoshSmith JoshSmith is offline
LED Junkie
FRC #0111 (WildStang)
Team Role: Mentor
 
Join Date: May 2011
Rookie Year: 2009
Location: Arlington Heights
Posts: 16
JoshSmith is an unknown quantity at this point
Re: Arduino PWM output

Quote:
Originally Posted by WizenedEE View Post
AFAIK we used the "stock" Arduino Wire library on this year's competition robot to communicate the shooter angular velocity with the cRIO.

We just had to use the transaction method of the I2C class.

relevant part of our code:
Code:
UINT8 valuesGotten[2] = {0, 0};
I2CArduino->Transaction(NULL, 0, valuesGotten, 2);
UINT16 fullNumber = (valuesGotten[1] << 8) | valuesGotten[0];
Full code for reading our sensor is attached. I don't currently have access to the arduino side, though.
Interesting. I know for this year I changed the Wire library to run at 38.4khz (what I was told was the digital sidecar's operating frequency for I2C) and just set the Arduino up as a slave device and it worked nicely. But anyways, I will stop myself now before I get too far off-topic. My recommendation on the shields is that if you plan on making more robots than cRIOs, then you should look at a shield as they will be cheaper than spending credits or money on an extra cRIO. Otherwise, if you have a cRIO lying around, just use that (providing you have a backup for your competition bot).

Last edited by JoshSmith : 28-05-2012 at 00:50.
  #17   Spotlight this post!  
Unread 05-06-2012, 19:24
sand500 sand500 is offline
Registered User
FRC #3540 (Wildcat Robotics)
 
Join Date: Jan 2011
Rookie Year: 2011
Location: United States
Posts: 81
sand500 is an unknown quantity at this point
Re: Arduino PWM output

I have a VEX Motor Module(3-wires) that our teacher had from a Vex Kit. I have the Arduino to slowly rise the PWM from 0-255 and then lower it down. What I have found is that the motor starts moving when the PWM is at around 40. I know that around 120, the motor starts slowing down and at 170, it stops completely. Once it is at 200, the motor starts again but in the opposite direction, slow at first but gets faster around 250. At 255, the motor stops completely and at 254, it starts again. Again the motor doesnt move when the PWM is between 200 and 170 and after that, it turns again in the original direction and stops at 40.

I dont know why this is happening but the duty cycle frequency was wrong, then why does it stop completely at 255? When I hook up the pwm and ground on the arduino to a regular dc motor that you would find in an electronics kit, the motor works just like how pwm should.


Here is the code I ran:
Code:
boolean increasing;
int x;
void setup() {
   x=0;
   Serial.begin(9600);  
increasing = true;
}

void loop() 
{
  
  
  Serial.println(x);
  analogWrite(9,x);
  
  if (increasing)
{
  x++;
} 
else
{
  x--;
}
  if(x==255)
  {
    increasing = false;
  }
  if (x==0)
  {
    increasing = true;
  }
  delay(500);
  
  
}
  #18   Spotlight this post!  
Unread 05-06-2012, 22:56
slijin's Avatar
slijin slijin is offline
Pockets
AKA: Samuel Lijin
FRC #0694 (StuyPulse)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York City
Posts: 537
slijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to behold
Re: Arduino PWM output

Quote:
Originally Posted by sand500 View Post
I have a VEX Motor Module(3-wires) that our teacher had from a Vex Kit. I have the Arduino to slowly rise the PWM from 0-255 and then lower it down. What I have found is that the motor starts moving when the PWM is at around 40. I know that around 120, the motor starts slowing down and at 170, it stops completely. Once it is at 200, the motor starts again but in the opposite direction, slow at first but gets faster around 250. At 255, the motor stops completely and at 254, it starts again. Again the motor doesnt move when the PWM is between 200 and 170 and after that, it turns again in the original direction and stops at 40.

I dont know why this is happening but the duty cycle frequency was wrong, then why does it stop completely at 255? When I hook up the pwm and ground on the arduino to a regular dc motor that you would find in an electronics kit, the motor works just like how pwm should.
I'm not too familiar with the VEX system, so take what I say with a grain of salt, but here's what I see happening:

The VEX motor module has built-in deadbands at 1) the neutral, which allows a user to feed a noisy joystick signal straight to the motor and 2) the ends, which either acts as a safety, to facilitate interfacing with the VEX system (due to hardware/programming constraints etc), or it was a design decision.

Hooking up this signal to a regular DC motor produces exactly that kind of behavior, not because it's how your signal "should" behave, but because it's how motors are expected to behave in response to such signals.
__________________

2010-12 CT Chairman's
2011 Galileo 5th seed
2010 NY Regional Winners
  #19   Spotlight this post!  
Unread 05-06-2012, 23:16
sand500 sand500 is offline
Registered User
FRC #3540 (Wildcat Robotics)
 
Join Date: Jan 2011
Rookie Year: 2011
Location: United States
Posts: 81
sand500 is an unknown quantity at this point
Re: Arduino PWM output

Quote:
Originally Posted by slijin View Post
I'm not too familiar with the VEX system, so take what I say with a grain of salt, but here's what I see happening:

The VEX motor module has built-in deadbands at 1) the neutral, which allows a user to feed a noisy joystick signal straight to the motor and 2) the ends, which either acts as a safety, to facilitate interfacing with the VEX system (due to hardware/programming constraints etc), or it was a design decision.

Hooking up this signal to a regular DC motor produces exactly that kind of behavior, not because it's how your signal "should" behave, but because it's how motors are expected to behave in response to such signals.
Why does the higher end of the pwm, have a smaller range, 200-255, while the lower end of the pwm has a bigger range, 40-170. When I was running the motor, I could see the motor hit a higher speed in the 40-170 range than in the 200-255. So why would a motor rotate faster in one direction than in another direction?
  #20   Spotlight this post!  
Unread 05-06-2012, 23:42
Gdeaver Gdeaver is offline
Registered User
FRC #1640
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 2001
Location: West Chester, Pa.
Posts: 1,357
Gdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond repute
Re: Arduino PWM output

Use the servo library.
  #21   Spotlight this post!  
Unread 06-06-2012, 00:02
slijin's Avatar
slijin slijin is offline
Pockets
AKA: Samuel Lijin
FRC #0694 (StuyPulse)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York City
Posts: 537
slijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to behold
Re: Arduino PWM output

Quote:
Originally Posted by sand500 View Post
Why does the higher end of the pwm, have a smaller range, 200-255, while the lower end of the pwm has a bigger range, 40-170. When I was running the motor, I could see the motor hit a higher speed in the 40-170 range than in the 200-255. So why would a motor rotate faster in one direction than in another direction?
Again, purely hypothetical here:

There are multiple reasons that this could happen, both electrical and mechanical.

On the electrical side, it could be an intentional design point (unlikely). It could also be that it's designed to take a different type of pulse (also unlikely). The most probable reason is an amalgam of 1) manufacturing inconsistencies and 2) a design "flaw" stemming from the circuit design (see the discussions about Victor and Jaguar signal driving; I can't do an explanation of these mechanisms justice, nor will I attempt to).

On the mechanical side, it could be a damaged bearing/bushing or shaft that gunks up in one direction and offers no resistance in the other (almost like a ratchet).
__________________

2010-12 CT Chairman's
2011 Galileo 5th seed
2010 NY Regional Winners
  #22   Spotlight this post!  
Unread 06-06-2012, 00:09
Greg McCoy's Avatar
Greg McCoy Greg McCoy is offline
boiler up!
FRC #3940 (CyberTooth)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Kokomo, IN
Posts: 484
Greg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond reputeGreg McCoy has a reputation beyond repute
Send a message via AIM to Greg McCoy
Re: Arduino PWM output

Quote:
Originally Posted by sand500 View Post
I dont know why this is happening but the duty cycle frequency was wrong, then why does it stop completely at 255?
The motor controller is behaving erratically because the PWM frequency and the duty cycle are wrong. The analogWrite() function is generating this PWM signal:


(from Arduino.cc)

...but your motor controller is expecting this:




The frequency of the signal in Hz is the number of pulses per second. The reciprocal of the frequency is the period, which is the time between the rising edges of the PWM signal. For your motor controller, this should be 50 Hz, or a 20 ms (millisecond) period. According to the Arduino documentation, the analogWrite() function produces a 490 Hz PWM signal, or a 2 ms period.


The duty cycle of the signal is the ratio between the pulse width and the period. For your motor controller, the pulse width is "mapped" as follows:

Full Forward: 2 ms pulse / 20 ms period = 10% duty cycle.
Neutral: 1.5 ms pulse / 20 ms period = 7.5% duty cycle.
Full Reverse: 1 ms pulse width / 20 ms period = 5% duty cycle.


As others have suggested, the Arduino servo library should be able to produce the correct signal. 180 degrees on a servo is the equivalent of "full forward" on a motor attached to the motor controller (0 degrees is full reverse, 90 is neutral, etc.)

Quote:
Originally Posted by sand500 View Post
When I hook up the pwm and ground on the arduino to a regular dc motor that you would find in an electronics kit, the motor works just like how pwm should.
The motor controller does just this - it generates a 0-100% duty cycle PWM signal to the motor, using a circuit called an "H-bridge" to reverse the voltage when changing directions.

Hope this helps...
  #23   Spotlight this post!  
Unread 06-06-2012, 00:15
slijin's Avatar
slijin slijin is offline
Pockets
AKA: Samuel Lijin
FRC #0694 (StuyPulse)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York City
Posts: 537
slijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to behold
Re: Arduino PWM output

Quote:
Originally Posted by Greg McCoy View Post
The motor controller is behaving erratically because the PWM frequency and the duty cycle are wrong
Can't believe I overlooked that. Should've been the first thing I realized.
__________________

2010-12 CT Chairman's
2011 Galileo 5th seed
2010 NY Regional Winners
  #24   Spotlight this post!  
Unread 06-06-2012, 04:41
Greg Needel's Avatar Unsung FIRST Hero
Greg Needel Greg Needel is offline
REVving up for a new season
FRC #2848 (All-sparks)
Team Role: Engineer
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Dallas, TX
Posts: 3,104
Greg Needel has a reputation beyond reputeGreg Needel has a reputation beyond reputeGreg Needel has a reputation beyond reputeGreg Needel has a reputation beyond reputeGreg Needel has a reputation beyond reputeGreg Needel has a reputation beyond reputeGreg Needel has a reputation beyond reputeGreg Needel has a reputation beyond reputeGreg Needel has a reputation beyond reputeGreg Needel has a reputation beyond reputeGreg Needel has a reputation beyond repute
Re: Arduino PWM output

I have a custom victor library for the arduino that was written for one of my projects. This takes care of the timing issues, and duty cycle issues. While the the stock servo library will work, there are things that will cause hiccups.

Edit, I have attached the files.


revictorlibsforarduino.zip

Greg
__________________
Greg Needel│www.robogreg.com
Co-founder REV Robotics LLC www.REVrobotics.com
2014 FRC World Champions with 254, 469, & 74

Last edited by Greg Needel : 06-06-2012 at 10:54.
  #25   Spotlight this post!  
Unread 08-06-2012, 16:59
sand500 sand500 is offline
Registered User
FRC #3540 (Wildcat Robotics)
 
Join Date: Jan 2011
Rookie Year: 2011
Location: United States
Posts: 81
sand500 is an unknown quantity at this point
Re: Arduino PWM output

Quote:
Originally Posted by Greg McCoy View Post
The motor controller is behaving erratically because the PWM frequency and the duty cycle are wrong. The analogWrite() function is generating this PWM signal:


(from Arduino.cc)

...but your motor controller is expecting this:




The frequency of the signal in Hz is the number of pulses per second. The reciprocal of the frequency is the period, which is the time between the rising edges of the PWM signal. For your motor controller, this should be 50 Hz, or a 20 ms (millisecond) period. According to the Arduino documentation, the analogWrite() function produces a 490 Hz PWM signal, or a 2 ms period.


The duty cycle of the signal is the ratio between the pulse width and the period. For your motor controller, the pulse width is "mapped" as follows:

Full Forward: 2 ms pulse / 20 ms period = 10% duty cycle.
Neutral: 1.5 ms pulse / 20 ms period = 7.5% duty cycle.
Full Reverse: 1 ms pulse width / 20 ms period = 5% duty cycle.


As others have suggested, the Arduino servo library should be able to produce the correct signal. 180 degrees on a servo is the equivalent of "full forward" on a motor attached to the motor controller (0 degrees is full reverse, 90 is neutral, etc.)



The motor controller does just this - it generates a 0-100% duty cycle PWM signal to the motor, using a circuit called an "H-bridge" to reverse the voltage when changing directions.

Hope this helps...
Thanks a lot, its a lot clearer to me now. I'll try Greg Needel's library and the servo library.
  #26   Spotlight this post!  
Unread 26-07-2012, 13:48
markgryzwa markgryzwa is offline
Registered User
FRC #3206 (Royal-T-Wrecks)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: MN
Posts: 30
markgryzwa is on a distinguished road
Re: Arduino PWM output

Here is some servo code that I put together to try to run some basic robot functions. I've not tested in out for polarity yet but the ideas are correct.

#include <Servo.h>

// global variables

// ------------- Servo setup ------------------------------
Servo myservo_left;
Servo myservo_right;

int left_pwm = 10; // set up the servo connections for the Jaguar controllers
int right_pwm = 9;
int rate = 0;


// ------- Spike relay control signals -------------------
int FWD = 1;
int REV = 2;
int OFF = 0;
int spike_white = 0; // pin 0 for spike signal wire
int spike_red = 1; // pin 1 for spike red wire


void setup() {
// put your setup code here, to run once:

myservo_left.attach(left_pwm);
myservo_right.attach(right_pwm);

pinMode(spike_white, OUTPUT);
pinMode(spike_red, OUTPUT);

}

void loop() {

// Set up the default
Spike(OFF);


// Make stuff happen
Forward(100, 1000); // move forward as a % of full speed for ms Foward(%*full speed,ms)
delay(1000);

Spike(FWD);
Reverse(100, 1000);
delay(1000);

Spike(REV);
Right(50, 100);
delay(1000);

Left(50,200);
delay(1000);

Spike(OFF);
Right(50, 100);
delay(6000);


}



//------------------ Subroutines ---------------------------

//-----------------------------------------------------------
void Forward(int rate, int duration) {

int spd = rate * 500; // set speed as a % of rate

myservo_left.writeMicroseconds(1500+spd);
myservo_right.writeMicroseconds(1500-spd);
delay(duration);
myservo_left.writeMicroseconds(1500);
myservo_right.writeMicroseconds(1500);
}

//-----------------------------------------------------------
void Reverse(int rate, int duration) {

int spd = rate * 500; // set speed as a % of rate

myservo_left.writeMicroseconds(1500-spd);
myservo_right.writeMicroseconds(1500+spd);
delay(duration);
myservo_left.writeMicroseconds(1500);
myservo_right.writeMicroseconds(1500);

}

//------------------------------------------------------------
void Left(int rate, int duration) {

int spd = rate * 500; // set speed as a % of rate

myservo_left.writeMicroseconds(1500+spd);
myservo_right.writeMicroseconds(1500+spd);
delay(duration);
myservo_left.writeMicroseconds(1500);
myservo_right.writeMicroseconds(1500);

}


//------------------------------------------------------------
void Right(int rate, int duration) {

int spd = rate * 500; // set speed as a % of rate

myservo_left.writeMicroseconds(1500-spd);
myservo_right.writeMicroseconds(1500-spd);
delay(duration);
myservo_left.writeMicroseconds(1500);
myservo_right.writeMicroseconds(1500);

}



//---------------------------------------------------------------
void Spike(int state) { //states can be 0=Off, 1 = FWD, 2=REV

switch (state) {
case 0:
digitalWrite(spike_red, LOW);
digitalWrite(spike_white, LOW);
break;

case 1:
digitalWrite(spike_red, HIGH);
digitalWrite(spike_white, LOW);
break;

case 2:
digitalWrite(spike_red, LOW);
digitalWrite(spike_white, HIGH);
break;

default:
digitalWrite(spike_red, LOW);
digitalWrite(spike_white, LOW);
break;
}

}
  #27   Spotlight this post!  
Unread 26-07-2012, 17:50
AlexH AlexH is offline
Registered User
no team
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2010
Location: PA
Posts: 215
AlexH is a name known to allAlexH is a name known to allAlexH is a name known to allAlexH is a name known to allAlexH is a name known to allAlexH is a name known to all
Re: Arduino PWM output

to run a victor with anything besides the current FIRST robot control system or the old IFI system you need a "signal driver cable" instead of a normal PWM cable.
__________________
My Instructables
  #28   Spotlight this post!  
Unread 26-07-2012, 18:07
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,038
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Arduino PWM output

Quote:
Originally Posted by AlexH View Post
to run a victor with anything besides the current FIRST robot control system or the old IFI system you need a "signal driver cable" instead of a normal PWM cable.
"Anything" covers a lot of ground. I'm not sure that's true.


  #29   Spotlight this post!  
Unread 26-07-2012, 22:47
Cuog's Avatar
Cuog Cuog is offline
Registered Linux User: 390661
AKA: Alex
FRC #0422
Team Role: Mentor
 
Join Date: Nov 2005
Rookie Year: 2004
Location: Richmond, Virginia
Posts: 852
Cuog has a reputation beyond reputeCuog has a reputation beyond reputeCuog has a reputation beyond reputeCuog has a reputation beyond reputeCuog has a reputation beyond reputeCuog has a reputation beyond reputeCuog has a reputation beyond reputeCuog has a reputation beyond reputeCuog has a reputation beyond reputeCuog has a reputation beyond reputeCuog has a reputation beyond repute
Send a message via AIM to Cuog
Re: Arduino PWM output

Quote:
Originally Posted by AlexH View Post
to run a victor with anything besides the current FIRST robot control system or the old IFI system you need a "signal driver cable" instead of a normal PWM cable.


I keep reading this on here but I have personally run an old blue label victor 883 directly from a 5v arduino(pro SMD version from sparkfun). Your mileage may vary of course.
__________________
KK4KQO
http://voltair.us
Too many projects, too little time.
  #30   Spotlight this post!  
Unread 26-07-2012, 22:54
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,740
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Arduino PWM output

That signal driver cable is only required to boost a standard RC receiver PWM signal to the level required by a Victor. An RC receiver normally drives servos and RC motor controllers that get by on a lower power signal.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 27-07-2012 at 09:22.
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 19:13.

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