Right now, I just have tank drive-2 motors, 2wheel drive setup, with two joysticks. No matter how far the joystick is pushed forward or backward, the motors turn the same speed. How can I set it up so that when pushed a little, the motor goes a slower speed, than pushing the joystick full throttle?
Reply With Quote
The default code turns on the motors at a certain voltage depending on how hard you press the joystick. Maybe your motors have such a high RPM you can’t see a difference. Try setting the PWM to a certain value and check the voltage on the Victors and see if they’re working right.
I edited the default code though
I take it from your terminology that you are using easyC. If so, wouldn’t this code work–see the attached screenshot…sorry, easyC won’t let me copy code out of it…
I don’t know much about easyC, so this might not be the right answer.
If you are using MPLAB:
pwm01 = p1_y;
pwm02 = p2_y
would map joystick 1’s y axis to pwm output 1, and joystick 2’s y axis to pwm output 2.
Ask if you need more help.
Good luck,
JBot
The joysticks output a value between 0 and 255 based on how far the joystick is pulled back. 0 is full back, 255 is full forward, 127 is neutral.
The speed of the motor is controlled using PWM, all you really need to know is that 0 is full back, 255 full forward, and 127 neutral.
Assuming your motor has fairly linear Power vs. RPM curve you should see a fairly linear response if you just do something like this:
PWM = joystick.
YOu can guarantee it by checking the values of the pwm outputs right before the PutData call at the end of Process_Data_From_Master_uP.
Since the PutData call is (essentially) when the data actually goes out to the robot, if the PWMs are the right value then, then you know that it isn’t a code problem.
Are you testing the motors with a load on them? They might spin fast even at low power settings if there is no load.
What did you edit it to? It should be easy for you to take what you changed and adapt it to match the joystick mapping in the default code.
You can directly map the joystick value to a PWM, as they are both in the 0-255 range with 127 being “neutral” or “off.” If you need to reverse the direction of a joystick to match your CIM configuration, you can just subtract the joystick axis from 255, like so:
pwm01 = p1_y; /* Left drive train maps directly from port 1 y axis to pwm01. */
pwm02 = 255 - p2_y; /* Right drive train does the same, but in reverse. */
To make things smoother (eliminate noise etc) you could use a lookup table to map joystick values.
You are using a victor controller for the motors and not a spike relay, right? :rolleyes:
using a victor
Good. Doesn’t hurt to check for simple problems. :o
Do the motors immediately start turning when the robot is reset?
Have you tried moving the centering dials beside the stick to center the joystick?
Are the PWM1 LEDS lit when the joystick is centered?
There is no change when you move either joystick? The motors don’t reverse at all?
Both joysticks do the same thing?
Can you copy the lines of code where you read one joystick value and then
assign it to the PWM output and post it here (or send it in a private message)?
Fire up the dashboard, connect your PC to the “dashboard” port on the OI, and check the PWM values there. They are changing, correct?
To check center on your joysticks, you can move the jumper just below the dashboard port and check the new screen. Center is 127.
The dashboard viewer is at http://www.ifirobotics.com/dashboard_viewer.shtml. Yes, 2005 is the latest and yes, it will work fine.
Another simple check: the victor controllers pwm’s are connected to the RC pwm 13,14,15 or 16. You can’t connect them to PWM 1 thru 12 … that’s from memory … if you do the victors will pick some speed and never change like you described.
Umm, I’m pretty sure Victors don’t care one way or another what PWM they’re on, in fact I don’t believe any of our robots use PWMs except 1-12 and they all work fine.
13-16 are different–the user processor must generate the signal, and because of this unless you have a special piece of code in place to generate the signal, these outputs will either be very quirky or not work at all.
JBot
Quite right the victors don’t really care what PWM you use. I was working from memory (don’t do that … read the manuals first before posting
However the original FRC code only drives 13-16 without you doing extra coding.
You might also want to look over here: http://www.chiefdelphi.com/forums/showthread.php?t=53527
another possible problem.
Umm…scratch that, reverse it. PWMs 1-12 are automatically generated. All you say is
pwm01 = 0;
to make it go full speed one direction,
pwm01 = 255;
the other way. 13-16 are quirky and you really probably don’t want to use them; you have to generate the signal yourself and tons of glitches were uncovered last year about using these channels.
JBot