Go to Post Conspire to Inspire despite what may transpire ! - Bill_B [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 19-02-2012, 13:29
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Dividing Speed on Robot Drive

I am trying to divide the speed of the motors...
by 1/2 when Button 1 of Stick 1 is pressed;
by 3/4 when Button 1 of Stick 2 is pressed; and
by 1/4 when Button 1 of Both sticks are pressed.

Where is the best place to add the divide function.

Code:
			// Drive
			if(J_stick1.GetRawButton(1) == true)
				R_myRobot.TankDrive(J_stick1, J_stick2);
			else
				if(J_stick2.GetRawButton(1) == true)	
					R_myRobot.TankDrive(J_stick1, J_stick2)*3/4;
				else
					if(J_stick1.GetRawButton(1) == true && J_stick2.GetRawButton(2) == true)
						R_myRobot.TankDrive(J_stick1, J_stick2)/4;
					else	
						R_myRobot.TankDrive(J_stick1, J_stick2);
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #2   Spotlight this post!  
Unread 19-02-2012, 14:58
SuperBK's Avatar
SuperBK SuperBK is offline
Registered User
AKA: BrianK
FRC #1225 (Amperage Robotics)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Henersonville, NC
Posts: 357
SuperBK is just really niceSuperBK is just really niceSuperBK is just really niceSuperBK is just really nice
Re: Dividing Speed on Robot Drive

It needs to be placed in the "IsOperatorControl()" loop where TankDrive() is being called now. call the GetY() method of the joysticks to get the value and multiply it by your scale. I would use decimals like 0.25. For example:

R_myRobot.TankDrive(J_stick1->GetY() * 0.25, J_stick2->GetY() * 0.25);

When you don't want to scale keep
R_myRobot.TankDrive(J_stick1, J_stick2);

In our example below, you forgot to multiply by 0.5 when button one was pressed.

You don't need "== true" in your checks for GetRawButton(). It returns a bool
__________________
Brian K
Team 1225 Robotics Mentor
Reply With Quote
  #3   Spotlight this post!  
Unread 19-02-2012, 21:19
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Dividing Speed on Robot Drive

You should have a scaleFactor variable and have the buttons modify it.
Code:
bool j1Btn1 = J_stick1->GetRawButton(1);
bool j2Btn1 = J_stick2->GetRawButton(1);
float scaleFactor = 1.0;
if (j1Btn1 && j2Btn1)
{
    scaleFactor = 0.25;
}
else if (j1Btn1)
{
    scaleFactor = 0.5;
}
else if (j2Btn1)
{
    scaleFactor = 0.75;
}
 
R_myRobot.TankDrive(J_stick1->GetY()*scaleFactor, J_stick2->GetY()*scaleFactor);
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 20-02-2012, 08:07
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: Dividing Speed on Robot Drive

Alright thanks, I did not know to use the GetY after the joysticks. For now it has all been working because I had just set the motors up as 2 different declarations and it worked there. So I will be switching it over today because its just much smoother.

Thanks,
Davis
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #5   Spotlight this post!  
Unread 20-02-2012, 10:34
jalburty jalburty is offline
Joe Alburty
AKA: Joe Alburty
FRC #1763 (Paseo Pirates)
Team Role: Mentor
 
Join Date: Oct 2006
Rookie Year: 2005
Location: Kansas City
Posts: 25
jalburty will become famous soon enoughjalburty will become famous soon enough
Send a message via ICQ to jalburty
Re: Dividing Speed on Robot Drive

Pardon my ignorance (or misreading of the post), but how do you get away with calling the TankDrive function (method?) with what looks like different data types as parameters? Is this what's known in C++ speak as "polymorphism"?

R_myRobot.TankDrive(J_stick1, J_stick2);
vs
R_myRobot.TankDrive(J_stick1->GetY() * 0.25, J_stick2->GetY() * 0.25);
Reply With Quote
  #6   Spotlight this post!  
Unread 20-02-2012, 11:32
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Dividing Speed on Robot Drive

Yes, that is polymorphism. Basically the function that is used is determined by the parameter types you pass into the function.

Inside the class it defines each different input parameter arrangement with the same function name, and you automatically select between those different functions by the parameters you provide.

Last edited by DjScribbles : 20-02-2012 at 11:33. Reason: small grammar fix
Reply With Quote
  #7   Spotlight this post!  
Unread 20-02-2012, 12:47
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Dividing Speed on Robot Drive

Quote:
Originally Posted by DjScribbles View Post
Yes, that is polymorphism. Basically the function that is used is determined by the parameter types you pass into the function.

Inside the class it defines each different input parameter arrangement with the same function name, and you automatically select between those different functions by the parameters you provide.
It is a form of polymorphism. Function overloading and templates are what is known as static polymorphism. When speaking with most C++ programmers though, polymorphism generally refers to dynamic polymorphism, implemented using function pointers and virtual functions. Static polymorphism is decided at compile time, and is based upon the visible type of the objects to the compiler. Dynamic polymorphism, however, is actually based upon the run-time type of the object.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:58.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi