View Full Version : FRC Code (Motors, etc...)
Raven_Writer
25-01-2004, 18:53
Ok, if my memory serves me correctly, the default code uses the PWM01 & PWM08 for motor movement. Is there a way to change this? Also, how do you use PWM's exactly (I was dropped from the programmer's group last year, so most of the stuff left my mind)?
Ok, if my memory serves me correctly, the default code uses the PWM01 & PWM08 for motor movement. Is there a way to change this? Also, how do you use PWM's exactly (I was dropped from the programmer's group last year, so most of the stuff left my mind)?
Look at their Default_Routine function in user_routines.c for their joystick code. Specifically, here:
/*---------- 1 Joystick Drive ----------------------------------------------
*--------------------------------------------------------------------------
* This code mixes the Y and X axis on Port 1 to allow one joystick drive.
* Joystick forward = Robot forward
* Joystick backward = Robot backward
* Joystick right = Robot rotates right
* Joystick left = Robot rotates left
* Connect the right drive motors to PWM13 and/or PWM14 on the RC.
* Connect the left drive motors to PWM15 and/or PWM16 on the RC.
*/
pwm13 = pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);
pwm15 = pwm16 = Limit_Mix(2000 + p1_y - p1_x + 127);
How do you use PWMs? Well, a lot could be said here, I suppose. The simple answer: set pwmXX to whatever value you want it set to! Then, make sure that you have the speed controller (or whatever else you're working with), hooked up, via a pwm cable, to the proper place on the controller (i.e., corresponding to what is used in the code, or either change which is used in the code to correspond to how you hooked up). A more specific question, (suprise), would elicit a more specific response, but ... All you really have to do is output some value to the variable pwmXX, and if you've got something plugged into the right pwm slot then it will do what it is supposed to (ideally :))
Ok, if my memory serves me correctly, the default code uses the PWM01 & PWM08 for motor movement. Is there a way to change this? Also, how do you use PWM's exactly (I was dropped from the programmer's group last year, so most of the stuff left my mind)?
Well let's get you aquainted to the robot and C...
The RC on the robot has multiple PIN spots, each with their own possible values. So, you can plug any speed controller / relay into any PWM. You have to make sure that you designate it in the code, though.
Here's an example: The default code mixes the X and Y values (X = Left/Right, Y = Up/Down) of one joystick on port 1. It then outputs it's values to PWM13, PWM14, PWM15, and PWM16.
And another example: Let's say that you want Tank Drive. Obviously, that means that the left motors move the same way and the right move the same way. Use the following code to get tank drive. (By the way, this assumes that you have two joysticks, each hooked up to the OI on ports 1 and 2. Also, make sure that PWMs 1 - 4 are not given values anywhere in your existing code)
pwm01 = pwm02 = p1_y; /* PWMs 1-2 are equal to each other, so put these on the left motors. p1_y means port 1, y-axis. So the left motors are controlled by one joystick when it is pushed forward.*/
pwm03 = pwm04 = p2_y; /* Much like the above code except that the PWMs are switched to 3-4 and p2_y is used instead. Connect pwm3-4 to your right motors.*/
I haven't tested that one exactly, but it should work.
Raven_Writer
26-01-2004, 07:21
Thanks to you both :)
I understand now (never quite understood how it all worked).
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.