View unanswered posts | View active topics It is currently Sun Nov 17, 2019 8:11 am






Reply to topic  [ 5 posts ] 
Change Direction and Reduce Speed -Tank Drive 
Author Message
Rookie

Joined: Tue Jan 06, 2015 1:50 pm
Posts: 3
Post Change Direction and Reduce Speed -Tank Drive
We have a simple "tank drive" robot that my team is trying to create code that would allow them to push a button and reduce power / slow down y1 and y2 on their robot (precision mode)...... and they are also wanting to program another button that would reverse the values from y1 and y2 that would make the "back" of their robot the "front" to be easier to drive for certain task. Appreciate any advice.

Thanks!


Tue Jan 06, 2015 1:57 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: Change Direction and Reduce Speed -Tank Drive
Okay, so for making a button to reduce the speed, you could have a variable that stores a value that you divide the y1 and y2 values by before you assign them to the motors. You'll also need a variable to store the previous press state of the button, if you want to make the button a toggle. So, something like:
Code:
float ScaleFactor = 1; // Stores the scaling factor
bool SpeedToggle = true; // Stores if the speed can currently be toggled

// Inside your main loop
if (// whatever button is pressed && SpeedToggle)
{
  if (ScaleFactor == 1)
    // Set scale factor to whatever slowdown you want
  else
    // Set it back to 1
  // Don't continue to toggle the scale factor back and forth for the same button press
  SpeedToggle = false;
}
else if (// whatever button is not pressed)
{
  // The scale factor can be toggled once again now that the button has been released
  SpeedToggle = true;
}


As for your second question, do you want to simply make the motors move the opposite way, or do you want to flip which stick corresponds to which side of the robot? In other words, after the flip, do you want the left stick to still control the actual left side of the robot or control what used to be the right side?

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Jan 06, 2015 3:05 pm
Profile
Rookie

Joined: Tue Jan 06, 2015 1:50 pm
Posts: 3
Post Re: Change Direction and Reduce Speed -Tank Drive
Thank you for your response. We would like to change the toggle switches so the left would then control the right going forward (backwards) and vice versa.

Below was our attempt at the reduce speed code. When we added the button code, we lost our deadzone??
(Also how does one share code for help with out it being "jumbled up"? I am new to the forum. I had to remove my //comments to get it to show up clean)

{
getJoystickSettings (joystick);

if(joystick.joy1_y1>20 || joystick.joy1_y1<-20),
{
motor[motorF]=joystick.joy1_y1;
}
else
{
motor[motorF]=0;
}

getJoystickSettings(joystick);


if(joystick.joy1_y2>20 || joystick.joy1_y2<-20)
{
motor[motorH]=joystick.joy1_y2;
}
else
{
motor[motorH]=0;
}

{
getjoystickSettings (joystick);

if(joy1Btn(6))
{
motor[motorF]=joystick.joy1_y1/4;
motor[motorH]=joystick.joy1_y2/4;
else
{
motor[motorF]=joystick.joy1_y1;
motor[motorH]=joystick.joy1_y2;
}


Thanks


Tue Jan 06, 2015 5:37 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: Change Direction and Reduce Speed -Tank Drive
So, to format code neatly, you can put it between [_code] and [_/code] tags, minus the underscores.
Now for the code. It looks like you want the reduced speed only while the button held? So, that does simplify things, but the reason to
use a variable to store the scale value is so that you can keep your deadzone. So, something like:
Code:
int scaleValue = 1;

getJoystickSettings (joystick);

if(joy1Btn(6))
{
  scaleValue = 4;
else
{
  scaleValue = 1;
}

if(joystick.joy1_y1>20 || joystick.joy1_y1<-20),
{
motor[motorF]=joystick.joy1_y1 / scaleValue;
}
else
{
motor[motorF]=0;
}

if(joystick.joy1_y2>20 || joystick.joy1_y2<-20)
{
motor[motorH]=joystick.joy1_y2 / scaleValue;
}
else
{
motor[motorH]=0;
}


By the way, just for reference, you only need one call to getJoystickSettings inside of your loop. :bigthumb:

As for switching which end of the robot is the front, that is a little bit more complicated. I think probably the easiest way is to just do an if statement to check if a button is pressed inside of your deadzone code. If the button is pressed, then make the joystick value negative and assign it to the opposite motor than normal. So, like:
Code:
if(joystick.joy1_y2>20 || joystick.joy1_y2<-20)
{
  if (// the button is pressed)
    motor[motorF]=-joystick.joy1_y2 / scaleValue;
  else   
    motor[motorH]=joystick.joy1_y2 / scaleValue;
}
else
{
motor[motorH]=0;
}

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Jan 06, 2015 11:16 pm
Profile
Rookie

Joined: Tue Jan 06, 2015 1:50 pm
Posts: 3
Post Re: Change Direction and Reduce Speed -Tank Drive
Thank you for your help and time. We are brand new to the world of RobotC and robotics. Your help is greatly appreciated.

Thanks!


Tue Jan 06, 2015 11:30 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.