Hello everyone,
Sorry about the wall of text ahead. I tried to include as much information as I could without going overboard. Recently I, the lead programmer on my team, have been working with a wireless Logitech controller (Wireless Gamepad F710) for single-operator control at a science fair or similar event. That way we can monitor safety better when there are younger children around. Everything works fine with that controller including driving, raising and lowering of firing mechanism, and firing said mechanism. The only problem is that we are for whatever reason unable to properly control a collecting function.
The mechanism consists of two SIM motors, two toothed belts, and a two wheels as a very basic explanation. See below for a video of it running. The two SIM motors are connected to a single Spark.
The code for our firing function and collecting function are exactly the same, except for opposite values being used to switch the direction of the SIMs.
Collect and Fire Functions:
void RunCollect(bool collectButton)
/* We grab these booleans from a separate .cpp and .h
to read the controller's values. More on that later. */
{
if (collectButton)
{
leftFireSpark.Set(1.0);
rightFireSpark.Set(1.0); //Not currently connected, will be implemented later
}
else
{
leftFireSpark.Set(0.0);
rightFireSpark.Set(0.0);
}
}
void RunFire(bool fireButton)
{
if (fireButton)
{
leftFireSpark.Set(-1.0);
rightFireSpark.Set(-1.0);
}
else
{
leftFireSpark.Set(0.0);
rightFireSpark.Set(0.0);
}
}
Their function is to run the motors in the specified direction as long as the specified button is held down, and stop the motors when the buttons are released. This code works for the firing.
Next I have provided the code for implementing the controller in the main Robot.cpp.
Robot.cpp Gamepad Implementation
Top level scope, within class:
MyJoystick* handheld = NULL; //We create a pointer to our MyJoystick class, which we know works because all of our other buttons work
In robot constructor:
handheld = new MyJoystick() //Just some initialization
In TeleopInit():
handheld->init(&controller);
//init function just sets up an array for the buttons, takes our "controller" Joystick which was declared earlier.
//We also know this works because it initializes and everything else works
And in TeleopPeriodic() we read the gamepad via “handheld->readJoystick();” and call the functions via “RunFire(handheld->readButton(6));” and “RunCollect(handheld->readButton(1));”
Once again, we know that this all works.
The problem manifests itself in a jittery, slow, barely moving rotation of the SIMs when collecting, regardless of button allocation. Firing, also regardless of button allocation, works great. The Spark lights a solid Red when calling the fire, but only occasionally flashes Green when calling RunCollect(). This issue also occurs when swapping the firing Spark with our right driving Spark, in which the new firing spark will not work when collecting. But the previous one works fine with driving. (We run a tank drive setup.) Additionally, we have tried switching PWMs to no avail. We’ve even rewired the motors to run in the opposite directions, and the collect button doesn’t work. We switched over to our identical 2-joystick (+ wired gamepad) setup and used the joysticks to run the motors, which worked flawlessly, so it seems to be a problem with the controller.
TL;DR: Something’s up with our controller and reversing our SIM motors. See above for code.
Video of it running: https://youtu.be/el7uBb7jzlQ
(Yes, the values are inverted so the motors run opposite, but the results are the same regardless of direction: RunFire works, but RunCollect does not.)
Any help would be appreciated!
Thanks,
RaskorTheWise
Penguin Empire (2551)