View unanswered posts | View active topics It is currently Sun May 24, 2020 6:22 pm

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Change Direction and Reduce Speed -Tank Drive
Author Message
Rookie

Joined: Tue Jan 06, 2015 1:50 pm
Posts: 3
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
Professor

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
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 factorbool SpeedToggle = true; // Stores if the speed can currently be toggled// Inside your main loopif (// 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
Rookie

Joined: Tue Jan 06, 2015 1:50 pm
Posts: 3
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
Professor

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
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.

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
Rookie

Joined: Tue Jan 06, 2015 1:50 pm
Posts: 3
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 5 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