A simple demo for using VEXLink with PROS
Report Bug
·
Request Feature
Table of Contents
This is a basic example of how you can use the PROS extension on VSCode and the VEXLink system to communicate with your device and your robot.
Here's why:
- Have you ever been working on auto and when you want to find coordinates you need to check either the brain or controller.
-
- Maybe your controller is in a place that is difficult to access
-
- Possibly in a match and you want to monitor how your coding is doing to make adjustments
-
- Maybe your controller is in a place that is difficult to access
- Need to check motor temps to see if their over heating
- Tuning PIDs
Of course, this is not a example to copy without understanding. It's important to understant how projects work in VRC. This README will explain how this works! 😄
This section should list any major frameworks/libraries in this example.
PROS 4
VEXLink Documentation
Here we'll explain the basic framework of this code.
Before we even start, if you haven't downloaded pros follow the instructions here.
With PROS 4 using the main.h file is absolutely necessary, if not used your program will error and fail. So the program starts by including this file:
#include "main.h"For this example I chose to take information from a motor. You may use any type of device in VRC that is legal. The general process stays the same. Refer to the PROS Documentation for information regarding taking information from external sensor and devices.
My code was the following:
pros::Motor motor(10, pros::MotorGears::blue); // Adding a Blue Motor to the port 10I also added a controller so I can control the speed of the motor to test my function. Refer to other repos for info on how to create this.
This is when things start to get a little tricky, however, they are still relatively simple. Let's go through it 🙂:
Right before we dig in, we surrond all of this in a while (true) loop, this insures that the program will continue to scan for new information. If we didn't have this then the data will only be sent once.
std::uint32_t motor_temp = motor.get_temperature(); // Get the motorTo explain this we need to dive into a bit of simple syntax:
std:: = refers to a common c++ library, named Standard Library
uint32_t = Unsigned Integers = integers only 0 and + numbers. The 32 refers to the size of the number:
| uint | Range |
|---|---|
| uint8_t | 0-255 (2^8) |
| uint16_t | 0-65536 (2^16) |
| uint32_t | 0-4294967296 (2^32) |
| uint64_t | 0-18446744073709551615 (2^64) |
Some sizes are overkill for our situation.
What I did for this was create my variable for motor temps, so I ended up using the uint32_t.
std::uint32_t motor_temp = motor.get_temperature(); // Get the motor
std::uint32_t motor_rpm = motor.get_actual_velocity();The next thing that we'll look at is the "if" "else" block of code:
We now are going to look to see if the data we are reciving is invalid its not the most important thing but it can be useful to have:
if (motor_temp == PROS_ERR_F) { // If the temperature reading is invalidNext, we tell the program what do do if there is an error:
printf("Error reading motor temperature\n");Next if this statement is false we use the else function and it will print the data on our screen.
} else { // If the temperature reading is valid
// Debug print to indicate the motor temperature
printf("| Motor Temp: %u C | RPM: %u \n", motor_temp, //the | are just to separate the columns of data.
motor_rpm);
}Finally probably the most important part of this function is the pros::delay(100), this simply tells the program to break, this is vital for all while loops and especially while multi-tasking. However this also tells our program the interval for sending information.
/*This is the main function that runs when the robot is turned on*/
void opcontrol() {
pros::Link link(21, "my_link", pros::E_LINK_TX); // Create a link radio
// Debug print to indicate that opcontrol is running
printf("opcontrol is running\n");
pros::Task task2(Data);
pros::Task task(spin);
}This is the brain of the program, while this program isn't the first to run it will run before the functions that you write. Knowing this we can define our radio here. we use the pros::Link function; we also need to define what we are defining which is a link. Then inside the () we will define the port that has the radio which in my case is port 21. Lastly we have to tell the program what this radio will do. Here it will transmit information your computer, so we define it as such.
E_LINK_TX = E_LINK_TRANSMITTER
The printf("opcontrol is running\n"); is a debugging feature that will show up in your pros terminal and will allow you know if everything is working.
Finally, we use the pros multi tasking to run both defining and sending the information.
WAIT!!! How do I even view the information???? Well, you found the place right here! The first thing your going to do is go to the PROS extension and click intergrated terminal:
The next thing you're going to do is run the following command into your terminal (make sure you've built and uploaded to project as once you've started its a pain and gerenally what Ii've done is unplug and repulg in my USB. If you have a better way put it under Issues):
pros terminalGREAT, now you can just run the program from either your controller or brain and it will send data live from your robot!
Contributions are AUSOME, so if you have any thing to add to make this better either add it as an Issues or see me in class.
Distributed under the MIT License. See LICENSE for more information.
