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.
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:
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.
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);
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.