I am a programmer working with another programmer on our team using V5 python on RobotMesh studio. I was fine-tuning our autonomous programs and driver control program when I decided I would place all my programs into one program for our competition. I wrote a menu code, tested it, then put it on the robot. I plugged in our old competition switch. No problems with the menu, no problems with our auton. The problem arose when we tried to run our driver control portion. After we switched from auton to driver, the robot quit the program. I’m pretty sure this happened after a second or two and not when I tried to use the joystick to move the robot. We did this many more times, trying to run driver first, changing our competition code (when I first started writing the program, I had a simplified version of an old competition template. This template matches up well with the new template, as in same commands, same functions, just some slight differences. Taking this into account, we copy pasted the code into the correct areas of the real template. Same issues, auton works, driver doesn’t. This wasn’t the problem). We then checked the code for syntax errors or indentation errors. We didn’t find anything. Not having many other options, I tried my regular driver code again just to make sure it works. No issue there. We tried in a fresh competition driver control just to get one motor to move. Upon further testing, it worked. Unfortunately, to get to the point it worked, I switched the switches back and forth multiple times, expecting a different outcome. The code ran and the motor moved. We tried a few other things rereading code, looking online, making small changes, commenting things. Nothing worked. We’re very confused as to why this is happening. Would anyone have a potential solution or a reason for why this happens? (After we gave up on trying to fix it, we tried to test the autonomous code and that stopped working as well. It happened at the end when we were leaving so we ran out of time and couldn’t try it again to make sure it wasn’t just chance)
Can you set your project to public and provide a link? I can take a look at it.
Here is our code
if button_X_current == True and button_X_previous == False():
will cause a type error.
Thank you very much! I will check to see if it works when I can
Thank you for the help! That was apparently one problem of many. One of the main reasons it didn’t work, I found out, was improper usage of variables. Having the variables outside the functions declared them as local instead of global, so when the code reached the places where the variables were called, it would quit the program because they weren’t defined. We put the variables inside the functions where it was mainly used to fix this problem. However, this created a new problem, as our autonomous competition function called a variable from another function. We fixed this by declaring it globally by doing
inside the function so it could be used by other functions, auto_select being the autonomous select variable for the multiple autonomouses (autonomi? autonomouse? autonomice?). This managed to fix the problem, and now the code runs smoothly. I also reduced the size of the autonomous code using functions so no one has to EVER AGAIN read through 62 blocks of 4 moving motor commands. Thank you again for all the help!