ROBOTC.net forumshttp://robotc.net/forums/ Single Joystick Control-Four motorshttp://robotc.net/forums/viewtopic.php?f=52&t=823 Page 1 of 1

 Author: 118steelhornets [ Wed Oct 15, 2008 10:27 am ] Post subject: 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...

Author:  Jeff McBride [ Wed Oct 15, 2008 10:55 am ]
Post subject:  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.

 Author: goteam237 [ Wed Nov 12, 2008 9:46 pm ] Post subject: 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]

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/