View unanswered posts | View active topics It is currently Tue Feb 21, 2017 3:33 am

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Single Joystick Control-Four motors
Author Message
Rookie

Joined: Tue Oct 07, 2008 9:51 pm
Posts: 6
Single Joystick Control-Four motors
how can i get the bot to move forward, backward, left and right on only ONE joystick? i can do forward and backward but not right and left...

Wed Oct 15, 2008 10:27 am
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Re: Single Joystick Control-Four motors
Assuming that you are talking about turning rather than sideways motion and you are using one joystick and two motor ports, you just need to use a little algebra like so:

 Code:void Arcade(int x, int y) // make joystick arcade style controller{    int powY;    int powX;    int powRightMotor;    int powLeftMotor;    // convert joystick -128 to 127 range to -100 to 100 for powering motors    powY = (y * 100) / 127;         // joystick y axis gives maximum power level    powX = (x * 100) / 127;         // x axis determines which motor is reduced or                                    // reversed for a turn    if (powX < 0) //  if x negative, turning left; otherwise, turning right    {        powLeftMotor = (powY * (100 + (2 * powX))/100); // left motor reduced for right turn        powRightMotor = powY;                           // right motor not changed    }    else    {        powRightMotor = (powY * (100 - (2 * powX))/100); // right motor reduced for left turn        powLeftMotor = powY;                            // left motor not changed    }    motor[motorRight] = powRight;    motor[motorLeft]  = powLeft;}task main(){    while (true)    {       getJoystickSettings(joystick);       Arcade(joystick.joy1_x1, joystick.joy1_y1);    }}

You can get more complicated than that if you want. It is useful to special-case hard right and hard left turns (joystick horizontal movement only, no vertical component) to force the robot to spin rapidly right or left. I'll leave that as an exercise for the reader.

_________________
Jeff McBride
Benson Robotics Club

Wed Oct 15, 2008 10:55 am
Rookie

Joined: Mon Oct 27, 2008 5:41 pm
Posts: 5
Re: Single Joystick Control-Four motors
would this work as a suitable solution to making the point turning using one joystick???

[code]
void Arcade(int x, int y) //make joystick arcade style controller
{
int powY;
int powX;
int powRightMotor;
int powLeftMotor;

// convert joystick -128 to 127 range to -100 to 100 for powering motors
powY = (y * 100) / 127; //joystick y axis gives maximum power level
powX = (x * 100) / 127; //x axis determines which motor is reduced or
//reversed for a turn

if (powX < 0) //if x negative, turning left; otherwise, turning right
{
powLeftMotor = (powY * (100 + (2 * powX))/100); //left motor reduced for right turn
powRightMotor = (powY * -(100 + (2 * powX))/100); //right motor is reversed
}
else
{
powRightMotor = (powY * (100 - (2 * powX))/100); //right motor reduced for left turn
powLeftMotor = (powY * -(100 + (2 * powX))/100); //left motor reversed
}

motor[driveright] = powRightMotor;
motor[driveleft] = powLeftMotor;
}
[/code]

Wed Nov 12, 2008 9:46 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 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

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