Our Auto for skills is working very strangely and does not work at all. We use an auton selector to select our different autos. When we select an auto, the radio blinks green, but the autonomous ONLY will move when we touch the robot. The robot will not do auto unless we move it even a little bit. I’ve linked our code below. How would we solve this problem?
assume you want to select an autonomous before connecting to field control, however, that loop is registering the ButtonLeft.pressed and ButtonA.pressed events many times. You must only register event handlers once.
also
Controller1.ButtonLeft.pressed([]() -> void {});
you cannot unregister an event handler unless you stop all tasks when the robot becomes disabled by setting bStopAllTasksBetweenModes to true.
see this post, make necessary changes and then see what happens.
The problem with the autonomous turned out to be an issue with the velocity scalar I had, robot works like normal now. However, I did have one question about calling the field control variables. From your thread, it seemed like I needed to move the callback into main. Would I need to move the WHOLE while loop or just the callback?
int main() {
// Set up callbacks for autonomous and driver control periods.
while (!autonSelected) {
Controller1.ButtonLeft.pressed(autonChanger);
Controller1.ButtonA.pressed([]() -> void {
autonSelected = true;
Controller1.ButtonLeft.pressed([]() -> void {});
Controller1.ButtonA.pressed([]() -> void {});
});
autonDisplay();
wait(100, msec);
}
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}```
read the topics I linked, never put event registration (the above code line) inside a while loop. every time you call pressed another function is registered. After a few loops many functions (in this case the same one) will be called every time the button is pressed.
I would rewrite the code using pressing() rather than using events.
here are a couple of options, although you probably figured this out already.
If you want to continue to use events.
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
// Run the pre-autonomous function.
pre_auton();
Controller1.ButtonLeft.pressed(autonChanger);
Controller1.ButtonA.pressed([]() -> void {
autonSelected = true;
});
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}