![]() |
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 |
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 |
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); |
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 |
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); |
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. |
Re: Dividing Speed on Robot Drive
Quote:
|
| All times are GMT -5. The time now is 17:36. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi