View unanswered posts | View active topics It is currently Sun May 24, 2020 7:34 pm

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
the programming problem of Joystick for tank mode
Author Message
Rookie

Joined: Thu Sep 26, 2013 9:50 am
Posts: 2
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Rookie

Joined: Thu Sep 26, 2013 9:50 am
Posts: 2
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"

{
//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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning