![]() |
Controlling motors
What part of the code controls the the motors. Our speed controls are calibrated but the motors do not spin when we use the joysticks. I'm guessing its somewhere in the programming.
|
Re: Controlling motors
The standard is in the "default routine" function, in user_routines.c. There, you assign operator inputs to pwm outputs. Also, in the "user initialization" function, make sure that the "default routine" function is not commented out.
|
Re: Controlling motors
In the defualt code, it goes as such.....
main()->Process_Data_From_Master_uP()->Default_Routine() The second two can be found in user_routines.c. Default_Routine() is not called from User_Initialization() by default. If you're using the 'bells and whistles' version of Kevin Watson's camera code, Default_Routine() is probably still commented out. To use the joysticks, the variables you need are p1_y and p1_x, where 1 is the number of whichever port your joystick is plugged into. The default code includes tank drive through pwm01 and pwm02, by assigning p1_y and p2_y to them, respectively. It also provides single joystick drive through pwm13 and pwm14 for the right wheel, and pwm15 and pwm16 for the left wheel. Although, some problems with this may arise from the fact that PWMs 13 - 16 are generated by the code and not by the microprocessor. If you want to use single joystick drive, I'd recommend assigning the equations that calculate the motor values to another set of PWMs. |
Re: Controlling motors
I am trying to set up a two joystick drive(tank drive) but I am a little confusing on how to actually go about doing this.
|
Re: Controlling motors
Quote:
pX_y is the value that we want. It's the value of the y axis on the joystick plugged into port X. So if you want to find the value of the y axis on a joystick plugged into port 1, it would be p1_y. These values are between 0 and 254. 127 is neutral, 0 is full reverse and 254 is full forward. Now look on your robot controller. There is a set of 16 3-pin male headers. This is where your motors are connected. They are labeled 1-16. Find out which one the motor you wish to control is on. You can set these motors to a value between 0 and 254, same as the joysticks. The macro for these is pwmXX where XX is a value between 01 and 16. To set it to a value you simply do pwmXX = 127; Now, linking them together. If a motor can take in a value between 0 and 254, and a joystick can output a value between 0 and 254, this becomes very easy. pwmXX = pZ_y; Where XX is the value between 01 and 16; depending on what port your motor is connected to. Z is varying depending on what port your joystick is connected to. Good luck. |
Re: Controlling motors
Thanks for all of your help. I got that to work but now how to I reverse one of the joysticks axis. One the right side of the robot when I move the joystick forward it makes the wheels on that side go in reverse.
|
Re: Controlling motors
That would be because your gearboxes or motors are mounted in opposite directions. The easiest way to remedy this problem is just to do something like this:
pwm01 = 254 - p1_y This would reverse the input from your joystick, but the problem that you'll run into is that the motors don't run in the same speeds forward and reverse, or even two motors going forward. You may have to develop a control system that tries to remedy this situation if it is really bad. |
| All times are GMT -5. The time now is 10:58. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi