|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
go like a tank
Hi,
Would like to write in easyC some come code for the motors to run like a tank. if y axis of joystick moved - move forward. (4 motors forward. 4 will reverse) if x axis changed - want to take a turn - move both sides same dir', only one will be slower. my question - need to be able to move one axis at a time. wrote: j1_y=GetOIAInput(1,1); j1_x=GetOIAInput(1,2) now I check which one is greater (there will also be a small deviation in x, even if move only in y direction, beacuse our hands are not that accurate...) so I "detect" the operator intention, and then write: SetPWM(motor according to comparator result, value) however, somehow, I still get movement in the other motor, connected to "axis x". howcome, if I didn't tell him SetPWM??? I thought how to check which is greater - beacuse maybe (-100,-20) the computer want to move towards -20, while intention is for -100. so I did abs function and then compared. However, I could do this since my assuption was that I have values between (127,-127) signed char from joystick. Is this correct assumption? If not, how can I solve this out, and decide which way to go, if I have values 0-255. since 127 is greater than 100, robot will not move, eventhough want to move to 100 location. (127 is stop as I recall). Can someone help? |
|
#2
|
||||
|
||||
|
Re: go like a tank
Why don't you just use the Tank 4 motor drive block? You just tell it which ports and it does it for you.
Has to your original question. You need two joysticks for tank drive. This should connect to 2 ports on the OI Port 1 and 2 are common. The code would be something like this. //variables unsigned char joy1_y unsigned char joy2_y //operator control code while(1) { joy1_y=GetOIAInput(1,2); //Port 1 Y-Axis 2); joy2_y=GetOIAInput(2,2); //Port 2 Y-Axis 2); SetPWM(1,joy1_y); //Left Motor 1 SetPWM(2,joy1_y); //Left Motor 2 SetPWM(3,joy2_y); //Right Motor 1 SetPWM(4,joy2_y); //Right Motor 2 } If you want to invert a motor then it would be SetPWM(1,255-joy1_y); Joysticks Return 0-255 Motors, Servos Accept 0-255 PrintToScreen is your friend ![]() Good luck Last edited by Kingofl337 : 19-01-2007 at 18:24. |
|
#3
|
|||
|
|||
|
Re: go like a tank
Quote:
why can't I use one joystick? (I want another joystick to control the arm) its y axis will control both motors on pwm 1,2. 1) What you say, is you think its better, becasue than I won't have the sensitivity problem? 2) if there is 1 joystick. x axis one motor. y axis other motor. I can't make it to move in only one direction. I wrote my approach in the thread, didn't understand why it didn't work 3) I tried "PrintToScreen", as I agree with you. It suppose to be my friend. It seems like there is a despute between us... It doesn't print to screen. After I download, controller starts running, and than it suppose to print whenever it's on the code, no? or should I do something else? 4) I am not infront of it now. easeC "help" also has explanations for how to use the remote control? Thanks! |
|
#4
|
||||
|
||||
|
Re: go like a tank
If you want to rotate in with X and Drive with Y on the joystick this function is called Arcade mode. Again there is a block that does this but you can use this code for mixing.
int LeftDrive, RightDrive; unsigned char Joy_Y, Joy_X; Joy_X = GetOIAinput(1,1); Joy_Y = GetOIAinput(1,2); Left = Joy_X - Joy_Y + 127; Right = Joy_X + Joy_Y -127; //Left motors SetPWM(1, Left); SetPWM(2, Left); //Right motors SetPWM(3, Right); SetPWM(4, Right); Yes the help file explains how to use the blocks. Last edited by Kingofl337 : 20-01-2007 at 20:24. |
|
#5
|
|||||
|
|||||
|
Re: go like a tank
There is no need to reinvent the wheel. Use what's given for the easy stuff. How about having fun by writing code to control 'straight ahead' with a gyro sensor, for example?
Don |
|
#6
|
|||
|
|||
|
Re: go like a tank
This is great when moving only in Y axis. so x=127. or only in X dir, so Y is 127.
But, what if by accident the operator moved in Y axis with a little deviation in x axis. I want to ignore X... i.e (j_x,j_y)=100,200 => left=27, right=173 => deviations from 127 are not the same: 100, -46 which is not good... instead of (j_x,j_y)=127,200 (the desired propogation) => left=200, right=54 (same deviation from 127) That's my intial probelm. Maybe I can check which one is closer to 127, and than force it to be 127. that it wil be good, no? |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tank Drive | Idaman323 | Programming | 14 | 15-02-2005 09:01 |
| 1 Clippard Tank ??? | Jeffrafa | Pneumatics | 15 | 12-01-2005 09:22 |
| Semi-Tank Tread/Half Tank Treads | thoughtful | Technical Discussion | 4 | 11-01-2005 08:33 |
| Like Father, Like Son | Koko Ed | Chit-Chat | 0 | 25-02-2004 23:31 |
| Under or Over? To tank or Not to tank that tis the question! | archiver | 2001 | 2 | 23-06-2002 22:53 |