I have been creating an object tracking program that uses the vision sensor and I wanted to have the robot turn itself to have the object at the center of the Y axis from the vision sensors point of view but I am unsure about how to write code that calculates this and moves the motors to center the object on the camera and what range of values the camera uses to find objects on the Y axis. Any advice is appreciated.
I am not sure how much you have accomplished with your program but here are some links to information on the Vision Sensor.
The sensor will return a value called centerY
that you can use math to determine if the robot should turn left or right.
//JPearman example
int TARGET = 150;
int error = obj.centerY - TARGET; //How far off center is the item.
// simple P control with a limit of 50
int drive = error;
if( drive > 50 ) drive = 50;
if( drive < -50 ) drive = -50;
// object is found and centered
if( obj.centerY > (TARGET-15) && obj.centerY < (TARGET+15) ) {
driveTurn(0);
}
else {
driveTurn( drive );
}
I have written code that can detect an objects positions and then send the centerX and centerY values to the terminal. Thank you for the sources. Now I just need to figure out specifically what their code is doing.
I have attempted to put this into a program but it seems that this program is made for Vex Coding Studio, how can I figure out to translate this into something that Vex V5 Pro C++ supports?
Go to file → import and select the file. Then save as to wherever.
Only one issue, Vex Coding Studio is discontinued and not available for download.
Pretty much all code from VCS can be used in VEXCode. Would it be possible to upload a .zip file of your VEXCode project that is causing an error?
On another note: The vision sensor has quite a lot of noise with x and y data values. I might suggest noise reduction methods like a simple rolling average, or look into more advanced filtering methods to help smoothen the data.
I would upload the files however I can’t go to the files and zip it since the computer I have been writing the code on is a school computer and the directory the project is stored in is restricted for some reason. Would it be more acceptable that I either upload the code in a post here or on github since all of it is really only in one file.
You could also Copy the files to a different directory, depending on how it is set up.
Can’t even do that unfortunately . The only thing that can be copied is text.