who can share a base code to guide me a little more I have the knowledge but I don’t know how to apply it for now I am using the PID denomination I would appreciate anyone who can help me
Make sure have read through Odometry - vex wiki
Here’s a basic outline
- Calculate the position of the encoders
- Find the change in position
- Update the stored previous values
- Convert the change in position from degrees to inches
- Find the robot angle
- Rotate the change in position to be global using the robot angle
- Add to the previous known x and y values of the robots.
Hello, yes I understand what you are saying, I have a clear concept but I don’t know how I could articulate it to Vex code V5 pro
First start with getting the position from your encoders
LEncoder = LB.position(degrees)
REncoder = RB.position(degrees)
then find the change in position and convert to distance. This works by converting degrees to radians and multiplying by the radius to find the arc length
distL = ((lEncoder - prevLE) * M_PI / 180) * lRad
distR = ((rEncoder - prevRE) * M_PI / 180) * rRad
then update the previous values
prevLE = LEncoder
prevRE = REncoder
find the average heading in radian (this will help with the trig later
Heading = ((gyro1.rotation()*M_PI/180))
then you rotate the change in local x and y using a rotation matrix
X += (deltaY * sin(averageHeading)) + (deltaX * cos(averageHeading))
Y += (deltaY * cos(averageHeading)) - (deltaX * sin(averageHeading))
then sleep the thread
this_thread::sleep_for(10)
repeat
this should be good enough to write it in vexcode pro v5
you would put this in a function with a while true loop and initialize it in a thread
Hello 2775Josh , thank you for your contribution, it is very effective, you help me a lot.
I have some questions, I would like to know if you could help me with this, I would appreciate it very much
Don’t ask to ask, just ask.
Thank you, my question is about what mathematical principles you based on to create your code, the idea is to understand how you structured your code as a guide to provide feedback against the concept you apply of odometry
I used nothing but the 5225A intro to position tracking document linked above. I couldn’t possibly explain odometry better than the document.