View unanswered posts | View active topics It is currently Sat Nov 29, 2014 3:30 am






Reply to topic  [ 4 posts ] 
the programming problem of Joystick for tank mode 
Author Message
Rookie

Joined: Thu Sep 26, 2013 9:50 am
Posts: 2
Post the programming problem of Joystick for tank mode
I want to use the Joysticks to control 4 motors. The following is the conventional programming, and it works well:

[
if(abs(joystick.joy1_y2) > threshold)
{
motor[frontRightMotor] = joystick.joy1_y2;
motor[rearRightMotor] = joystick.joy1_y2;
}
else
{
motor[frontRightMotor] = 0;
motor[rearRightMotor] = 0;
}
if(abs(joystick.joy1_y1) > threshold)
{
motor[frontLeftMotor] = joystick.joy1_y1;
motor[rearLeftMotor] = joystick.joy1_y1;
}
else
{
motor[frontLeftMotor] = 0;
motor[rearLeftMotor] = 0;
}
]

But now, when I want to using one Joystick to control all the four motors by the following codes, the program can not work correct:

[
if(abs(joystick.joy1_y1) > threshold)
{
motor[frontRightMotor] = joystick.joy1_y1;
motor[rearRightMotor] = joystick.joy1_y1;
motor[frontLeftMotor] = joystick.joy1_y1;
motor[rearLeftMotor] = joystick.joy1_y1;
}
else
{
motor[frontRightMotor] = 0;
motor[rearRightMotor] = 0;
motor[frontLeftMotor] = 0;
motor[rearLeftMotor] = 0;
}
]
The problem is that the right motors can not work, and the left ones' speed is not correct.

If someone can explain the problem that would be awesome!

Thanks a lot!


Thu Sep 26, 2013 10:16 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: the programming problem of Joystick for tank mode
What is your expected behavior? Your code only allows the robot to go forward and backward using the y1 axis. It doesn't do turns. Is this your intention? Put the robot on blocks so that the wheels are off the ground and tell us what the four wheels are doing when you pushing the y1 axis control?
You may want to post the entire code just to let us see if all the other declarations are correct.


Thu Sep 26, 2013 4:26 pm
Profile
Rookie

Joined: Thu Sep 26, 2013 9:50 am
Posts: 2
Post Re: the programming problem of Joystick for tank mode
Well, thanks, MHTS

I just want to let the left y-axis to control the robot forwards and back, meanwhile the right x-axis to turn. the codes are following.
[

#pragma config(Hubs, S1, MatrxRbtcs, none, none, none)
#pragma config(Motor, mtr_Matrix_S1_1, FLMotor, tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor, mtr_Matrix_S1_2, FRMotor, tmotorTetrix, PIDControl, encoder)
#pragma config(Motor, mtr_Matrix_S1_3, RLMotor, tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor, mtr_Matrix_S1_4, RRMotor, tmotorTetrix, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#pragma debuggerWindows("joystickSimple");
#include "JoystickDriver.c"

task main()
{
//less than the threshold will be ignored.
int threshold = 10;

while(true) //Loop Forever
{
//Get the Latest joystick values
getJoystickSettings(joystick);

//Driving Control
//left y
if(abs(joystick.joy1_y1) > threshold)
{
motor[FRMotor] = joystick.joy1_y1;
motor[RRMotor] = joystick.joy1_y1;
motor[FLMotor] = joystick.joy1_y1;
motor[RLMotor] = joystick.joy1_y1;

}
else
{
motor[FLMotor] = 0;
motor[RLMotor] = 0;
motor[FRMotor] = 0;
motor[RRMotor] = 0;
}
//right x
if(abs(joystick.joy1_x2) > threshold) //
{
motor[FRMotor] = -joystick.joy1_x2;
motor[RRMotor] = -joystick.joy1_x2;
motor[FLMotor] = joystick.joy1_x2;
motor[RLMotor] = joystick.joy1_x2;

}
else
{
motor[FLMotor] = 0;
motor[RLMotor] = 0;
motor[FRMotor] = 0;
motor[RRMotor] = 0;
}
}
}

]

The strange thing happen when "abs(joystick.joy1_y1) > threshold" is true, all the four motors can not work correctly.

What's the problem?

Thanks again!


Thu Sep 26, 2013 8:42 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: the programming problem of Joystick for tank mode
There's your problem. Look closely at your code. What happened when you push y1 axis but not touching x2 at all? Run the code through you head and you will see why it doesn't work.


Fri Sep 27, 2013 12:00 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.