View unanswered posts | View active topics It is currently Fri Oct 31, 2014 11:02 am






Reply to topic  [ 3 posts ] 
Single Joystick Control-Four motors 
Author Message
Rookie

Joined: Tue Oct 07, 2008 9:51 pm
Posts: 6
Post 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
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post 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
Profile
Rookie

Joined: Mon Oct 27, 2008 5:41 pm
Posts: 5
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.