Hello everyone! I wrote this little program a while ago and shared it with some folks on Discord. Here it is for everyone on the VEX forum to see, too.
What is it?
This program can record what motors are told to do, play back those recordings, and save/load them to/from an SD card.
How is it used?
Each motor that we’re interested in recording gets set up as a special velocityRecordedMotor, which extends vex::motor. From there, you can just use the
spin method on the new velocityRecordedMotor object like you would on a vex::motor. When you set up a velocityRecordedMotor, you also specify a filename for that particular motor to use as its logfile on the SD card.
How does it work?
The magic happens in how vex::motor::spin has been overridden, and the additional things that have been added as part of velocityRecordedMotor. The additional elements affect how the new
spin method works. If playback is turned on, calling
spin will ignore any arguments and instead send the appropriate saved command to the motor. If instead recording is turned on, calling
spin will save the command and move the motor. (If neither playback nor recording is active, it will behave like a regular driver control program.)
How would I use this for an autonomous routine?
To use this for an autonomous routine, you would run a driver controlled version of your autonomous with recording active, then save the recording to an SD card. In preautonomous, you would load those recordings from the SD card to the working memory of the appropriate velocityRecordedMotors (using the handy
loadRecording method). In the autonomous function itself, you would begin playback for each motor (with
enablePlayback), then run a copy of the driver code that produced the recording.
In fact, you could simply eschew the typical competition template altogether. You could put your driver code in the main function, then all you would have to do is call
enablePlayback when autonomous starts and
disablePlayback when autonomous ends. Autonomous selection would come down to choosing which recording should be loaded from the SD card. (As written, each motor can only reference one file. Changing which file a motor wants to load from and save to is left as an exercise for the students.)
Can I copy this?
If you would like to, sure! If you intend to use any part of it for competition, though, be sure to study it and understand how it works so you don’t get dinged for <G2>. To make a copy of a program in Robot Mesh Studio, click the options gear icon at the top right, click “Copy Project”, and you’re off to the races.