RobotC drive program issues

We have our first competition of the season coming up very soon and we are having some issues getting the drive program to work correctly. Can anyone offer some insight, or point me in the right direction to keep researching? We use RobotC graphical and are a Middle School team in our third and final IQ season; the boys are moving into more complex builds and programs, but we all only have middling programming knowledge.

Problems:

  1. We need all the buttons and the drive train to be able to work at the same time. Currently, each works individually (mostly) but we can’t operate other things. For instance, we need the intake wheel to be turning at the same time sometimes as the pick-up tube tread but can’t get both going at once. Do we need to imbed bed each command in an ongoing if/else? We created and tested each button separately, so maybe this has to do with just putting each separate command in the repeat forever one after another.

  2. We’ve been working on a section of code using the new graphical variables, which we haven’t worked with before. What we’re trying to do is create a toggle button that allows us to push the button once to turn on and then again to turn off a motor (leaving it running until button is pressed again). It actually works, sort of! However, you have to push the button over and over and over and then woohoo! it worked! and then push over and over… I assume it has something to do with the loop and getting in and out of it and needing possibly to add a wait to pause somewhere, but we haven’t been able to fix it yet.

Thanks!
Laura



The general structure of your teleop program looks good - it uses infinite loop, evaluates the controls and turns the motors on and off accordingly. setMotor/stopMotor are safe commands for such a structure. But in some cases, you use moveMotor, or even explicit wait, during which none of your joystick evaluation runs. moveMotor is a blocking function, it keeps running to completion and nothing else will happen in your program before it finishes. But the other motors will keep doing whatever they did before (e.g. keep moving forward, no matter where the joystick is).
If you need to move motor to a given position instead of start at given speed, you can use a non-blocking command set/moveMotorTarget. That command will initiate the action, but let your program keep going (looping the control loop) while the motor is moving independently to that position.
You need to avoid sending any other command to that motor though, as it would cancel the operation.
If your robot needs to do a sequence of moves, you can either add variables to form a state machine, or/and test some implicit state as another event trigger. For toggles, you need a way to recognize whether the button was released in the mean time. In a back-to-back if(pressed) { /* turn it on }; if (running && pressed) { / turn it off */ }, you’ll get it both started and stopped within a millisecond on that single press inside a single control loop iteration.

I should add that to have setMotorTarget command available, you need to set your RobotC to “Expert” menu level mode. Go to Window->Menu Level->Expert (or even Super User, no harm done ;-))

Thanks! We ended up going with a much more simplistic drive code where each button operates a motor in forward or reverse and only when pushed; we were out of time and needed something to use at the competition! It works, but it definitely limits what we can do (since we’re out of buttons). I’ll see if we can revisit the toggle code before our January competitions; we’re also doing some robot tweaking to try and improve performance.