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.
Can I copy this?
Not for use in VRC (or VIQC), no. Using code written by an adult such as this is not within the intent of rule G2 in VRC/VIQC. As it was written by an adult, this code is not legal for VRC/VIQC competition use. It is only provided as a learning tool to show how the SD card could be used. If you do still want to write something like this to use in competition, don’t use my version, as it’s not only against the rules but also not very useful: you can’t hand-edit a recording to do minor tweaks, it has some catastrophic interactions with competition template control, and it makes no allowances for running different autonomous routines.
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.)