View unanswered posts | View active topics It is currently Tue Sep 02, 2014 10:12 pm






Reply to topic  [ 6 posts ] 
Help making arcade drive instead of tank? 
Author Message
Rookie

Joined: Sun Feb 02, 2014 4:09 pm
Posts: 3
Post Help making arcade drive instead of tank?
Hey guys I need help with making arcade drive, I would like to try out arcade drive instead of using tank all the time.

Code:
#include "JoystickDriver.c"

task main()
{
  int deadZone = 10;             
                                 

  while(true)                            // Infinite loop:
  {
    getJoystickSettings(joystick);
   
    if(abs(joystick.joy1_y2) > deadZone)   
    {
      motor[driveL] = -joystick.joy1_y2 * 100/128;         
    }
    else                                   
    {
      motor[driveL] = 0;                       
    }


    if(abs(joystick.joy1_y1) > deadZone) 
       
      motor[driveR] = joystick.joy1_y1 * 100/128;       
    }
    else                                   
    {
      motor[driveR] = 0;                       
    }
  }
}


Thanks for looking! :bigthumb: :D


Sun Feb 02, 2014 4:14 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Help making arcade drive instead of tank?
I'm not entirely sure what 'arcade drive' is to you - but to me, that would mean push one stick forwards it goes forwards, left/forwards it stops the left track, left it turns in place left, etc.

If so, this can be accomplished using something called a virtual subtractor mechanism. Great technic builder Sariel has a good write up about one here. http://sariel.pl/2012/10/nxt-virtual-subtractor/

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sun Feb 02, 2014 4:21 pm
Profile WWW
Rookie

Joined: Sun Feb 02, 2014 4:09 pm
Posts: 3
Post Re: Help making arcade drive instead of tank?
NeXT-Generation wrote:
I'm not entirely sure what 'arcade drive' is to you - but to me, that would mean push one stick forwards it goes forwards, left/forwards it stops the left track, left it turns in place left, etc.

If so, this can be accomplished using something called a virtual subtractor mechanism. Great technic builder Sariel has a good write up about one here. http://sariel.pl/2012/10/nxt-virtual-subtractor/



Thanks, but i'm still confused, i'll comment what I don't understand in the code:

Code:
task main()
{
  bMotorReflected[motorA] = false;
  bMotorReflected[motorB] = false;
  while(true)
  {
    getJoystickSettings(joystick);
    motor[motorA] = 0;
    motor[motorB] = 0;
    if (joystick.joy1_y1 != -6) // Why is -6 chosen as a value for?
    {
      motor[motorA] = joystick.joy1_y1 / 1.28;
      motor[motorB] = joystick.joy1_y1 / 1.28;
 
      if (joystick.joy1_x1 != -5) // Here again why is -5 chosen?
      {
        motor[motorA] = (joystick.joy1_y1 + joystick.joy1_x1) / 2.56; // Are both of these two used when it's diagonal? And cut to half
        motor[motorB] = (joystick.joy1_y1 - joystick.joy1_x1) / 2.56;  // speed? What does it do exactly?
      }
    }
    else if (joystick.joy1_x1 != -5) //Again -5? Is it not same as above? Is this for when y1 has no value and this is just to spin l/r?
    {
      motor[motorA] = joystick.joy1_x1 / 1.28;
      motor[motorB] = joystick.joy1_x1 / -1.28;
    }
 
    nxtDisplayCenteredTextLine(0, "BATTERY: %3.1fV", nImmediateBatteryLevel / (float) 1000);
    nxtDisplayTextLine(2, "Y1: %d", joystick.joy1_y1);
    nxtDisplayTextLine(3, "X1: %d", joystick.joy1_x1);
  }
}


Mon Feb 03, 2014 12:47 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Help making arcade drive instead of tank?
In arcade drive, we use the x-axis of the joystick to control the turning power and the y-axis to control the driving power. When x-axis is reading zero, both left and the right wheels get the y-axis value as the driving power so it drives forward or backward. When x-axis reads some positive value, we add the value to the left wheel power and subtract the value from the right wheel power so it will turn right. Similarly, when x-axis reads some negative value, the same operation will turn left. So the simplest arcade drive algorithm is like this:
Code:
#define DEADBAND(n, t)    ((abs(n) > (t))? (n): 0)
#define BOUND(n, lo, hi)   (((n) < (lo))? lo: ((n) > (hi))? (hi): (n))

while(true)                            // Infinite loop:
{
    getJoystickSettings(joystick);

    int drivePower = DEADBAND(joystick.joy1_y1, deadZone)*100/128;
    int turnPower = DEADBAND(joystick.joy1_x1, deadZone)*100/128;

    motor[driveL] = BOUND(drivePower + turnPower, -100, 100);
    motor[driveR] = BOUND(drivePower - turnPower, -100, 100);

    wait1Msec(100);
}


Mon Feb 03, 2014 2:16 am
Profile
Rookie

Joined: Sun Feb 02, 2014 4:09 pm
Posts: 3
Post Re: Help making arcade drive instead of tank?
MHTS wrote:
In arcade drive, we use the x-axis of the joystick to control the turning power and the y-axis to control the driving power. When x-axis is reading zero, both left and the right wheels get the y-axis value as the driving power so it drives forward or backward. When x-axis reads some positive value, we add the value to the left wheel power and subtract the value from the right wheel power so it will turn right. Similarly, when x-axis reads some negative value, the same operation will turn left. So the simplest arcade drive algorithm is like this:
Code:
#define DEADBAND(n, t)    ((abs(n) > (t))? (n): 0)
#define BOUND(n, lo, hi)   (((n) < (lo))? lo: ((n) > (hi))? (hi): (n))

while(true)                            // Infinite loop:
{
    getJoystickSettings(joystick);

    int drivePower = DEADBAND(joystick.joy1_y1, deadZone)*100/128;
    int turnPower = DEADBAND(joystick.joy1_x1, deadZone)*100/128;

    motor[driveL] = BOUND(drivePower + turnPower, -100, 100);
    motor[driveR] = BOUND(drivePower - turnPower, -100, 100);

    wait1Msec(100);
}



Thanks I got it work, now I just need help allowing switch between tank and arcade? Using joy2Btn? or something so if the button was pressed just once then it will be tank then pressed again it will be arcade? How can I do that?


Tue Feb 04, 2014 10:04 pm
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 103
Post Re: Help making arcade drive instead of tank?
Yes, you could use joy1Btn() or joy2Btn() to check to see if a specific button is pressed. If that button is pressed you could toggle a Boolean variable that indicates whether the robot is in tank drive or arcade drive mode. Also, you'll need to keep track of if the button was pressed the last time you checked it, to make sure that you don't change the mode more than once per button press.

_________________
Burning Lights Programming
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
Check out our team website at http://cof7468.weebly.com/.


Tue Feb 04, 2014 10:42 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.