I’m a high school teacher working on a project using VEX V5 Components.
Students are making a “Mario Kart” game where two people race two small karts head to head. The project has to use sensors, so the students put Optical sensors on the karts that can interact with the track. Like Mario Kart, they want to have a spot for a speed boost, and a spot to slow down the kart to give the other kart an advantage. We were using Drivetrain controls, but that didn’t work at all, so we switched to using Controller.Axis.Position. For testing, we are using pretty drastic slowdowns and speed increases, but plan on the standard drive speed to be 75%, Speed Boost at 100%, and the Slow Down at 50%. Right now standard speed is 50%, slow down is 10%, speed boost is 100%. The following code works, but only when the kart is on a certain color, and it changes the moment it drives forwards off of it.
(Forgive the formatting, this is my first time posting)
while (true) {
if (Optical12.hue() > 0 && Optical12.hue()<46) { //Sees Yellow
Motor5.spin(forward, Controller1.Axis2.position()*.1, (percent));
Motor6.spin(forward, Controller1.Axis3.position()*.1, (percent));
}
if (Optical12.hue()>60 && Optical12.hue()<70) { //Sees Green
Motor5.spin(forward, Controller1.Axis2.position(), percent);
Motor6.spin(forward, Controller1.Axis3.position(), percent);
}
else {
Motor5.spin(forward, Controller1.Axis2.position()*.5, (percent));
Motor6.spin(forward, Controller1.Axis3.position()*.5, (percent));
}
}
Now the issue comes in. We don’t want the speed boost, nor the slow down, to be only while driving over that color. If a robot drives over a yellow piece of paper, we want it to slow down for 5 seconds while still being fully controllable. We added a wait function so the code looks as follows:
while (true) {
if (Optical12.hue() > 0 && Optical12.hue()<46) { //Sees Yellow
Motor5.spin(forward, Controller1.Axis2.position()*.1, (percent));
Motor6.spin(forward, Controller1.Axis3.position()*.1, (percent));
wait(5,seconds);
}
if (Optical12.hue()>60 && Optical12.hue()<70) { //Sees Green
Motor5.spin(forward, Controller1.Axis2.position(), percent);
Motor6.spin(forward, Controller1.Axis3.position(), percent);
wait(5,seconds);
}
else {
Motor5.spin(forward, Controller1.Axis2.position()*.5, (percent));
Motor6.spin(forward, Controller1.Axis3.position()*.5, (percent));
}
}
SO THE ISSUE!
The brain stores whatever the axis position was when the robot saw the color, modifies it accordingly, and holds that for 5 seconds. So if the robot is driving straight at 50% and senses green, it speeds up to 100%, but cannot be controlled, so it just drives straight at full speed for 5 seconds, not allowing the driver to turn or slow down if they choose.
We’ve been messing around with a for loop that counts to 5 seconds, and also using a float called speedmod that changes in the code and is used to modify the position, but no luck.
The kart either doesn’t maintain the newly set speed once it drives off the color, or holds on to whatever the input of the controller axis was and modifies it for 5 seconds.
Any help would be greatly appreciated!! Thank You!!
edit: code tags added by mods, please remember to use them.