Vex IQ — Data Logging with SD Card (VexCode 4.0 SWITCH)

Matthew Chou
4 min readSep 20, 2024

--

VexCode v4 has several new features. In this blog, I would like to share with you a new use of Switch that can be a game changer for people who use Block Code. Watch the video above for more details. To download the demo code in this story, click here.

Sensor output

It is essential to know the sensor data and the control value during design and configure an autonomous program. Several place to output sensor data in VexIQ. The LED screen, the consol in VexCode and the SD disk.

However, LED screen is too small to hold many data and can be inconvenient to read. The Console window requires USB-C wire connection all the time. The wire may interfere with the run.

Before VexCode v4, write data to file was only possible for people writing Python or C++. The Switch opens the door for Block Code.

Syntax

brain is an object instance of the Brain class. When the VexCode project is created, the brain object is automatically created. sdcard is an object in brain. It is not in the pick list when you type in the dot. You have to type in all small case. Same as savefile method under sdcard. FileName is a string and Record is the data we want to add to the file.

Data Format

Everything between quotation mark is a string. Plus sign concatenate two Strings. Percentage sign % is a specifier. “%1.0f” % Counter format the value into a string: at least 1 digit above decimal; 0 digit below decimal; and Counter is a floating point number.

Slash ( \ ) is an escape sign in a string. \n means the end of current line. Anything after this point goes to the next line.

+= append following string to the current string.

Use Case — Can my motor reach 100% speed?

Motor has maximum output torque and speed. With the load and gear ratio on the robot, can my driving motor run at 100% speed when I set velocity to 100%? This is an important step to design motor velocity based PID control.

Looking at three experiments, the maximum motor speed reported by the motor seems to be around 70 to 80 percent. Surprisingly, the reading from motor feedback fluctuates a lot even though the traveling speed is visually consistent. We now know that we might not want to use this reading to make decisions.

Use Case — What is my actual maximum speed?

Since the velocity of motor feedback fluctuates, we don’t want to use this value to figure out the maximum motor speed. Instead, we can set experiment on multiple motor speed and check the total run time as our measure. Start from setting motor to 100% velocity, then 90%, 85%, 80% 75%. We notice that the total run time when we set motor to 100%, 90%, 85% and 80% are not significant different. But when we set motor velocity to 75%, the total run time significantly increase. Now we know that the actual maximum speed is somewhere between 75% to 80%.

Finally

In this blog we explore the possibility of using SD card to record the sensor reading and control value during a run. With VexCode 4.0, this option is open to Block Code as well. This is an addition to the VexIQ PID autonomous programming series.

--

--

Matthew Chou

My name is Matthew Chou and I am an experienced Vex programmer. My goal is to share with you all the secrets to coding in vex to instantly improve your score!