Lesson 18 - Extended Printing to Terminal
In our previous “Printing” lesson, we taught you how to use printing in C++ to display values in the terminal. In actuality, the usefulness of printing can be extended beyond what we showed before.
When working directly with functions and output, we already covered basic debugging (such as printing out values to the terminal in order to keep track of variables that may be going awry). However, there are other uses of printing that can be utilized when programming in VEX. Mainly, you can print the output values of V5 electronics such as the built-in motor IMUs, VEX sensors, and more.
Let’s say you are programming your autonomous code, you could use printing to terminal in order to find the amount of encoder ticks it takes for your chassis to travel to a designated target. For example, after pushing your chassis in a straight line for the designated length, you could use:
std::cout << motorName.get_position() << std::endl;
Let’s consider another example. Let’s say you wanted to print the position of the chassis, in particular BOTH the encoder values and the orientation (IMU) at all times. You could do this through the following code.
std::cout << “Right Motor Position: “ << right_motor.get_position() << “ Left Motor Position: “ << left_motor.get_position() << “ Orientation: “ << imu.get_rotation(); << std::endl;
As well, you could keep track of a sensor’s position (like the value given by a potentiometer) by doing:
std::cout << sensorName.get_value() << std::endl;
The potentiometer’s value will be printed by the terminal every time the program iterates. This could be useful for finding the right height a lift may have to be at during the autonomous period or in order to find a height preset that may be useful in the usercontrol period.