I’m am working on a simple posistion tracking program in V5 Blocks. The only formulas used to get the coordinates are:
X = r cos(theta)
Y = r sin(theta)
The problem with this code is when my heading changes it seems to turn the robot(red circle) around a radius. Im not very experienced with coding so any help or examples will be appreciated!
I’m not sure how you would do this using blocks, but the way it’s done in text is to have a variable that stores the previous value of the encoders, which is updated to the current value at the very end of the loop. And then the variable storing the current value is updated at the start of the loop. What that means is that when referencing the current and previous encoder variables, the previous one is always one cycle of the loop behind the current one.
With that you can just do the current position - the past position to get the change in position.
I think the issue now is that you are using multiple forever loops, so instead of doing the setting and updating of the encoder values in the right order with the coordinate setting, you’re doing it all at once in parallel. Try putting it all in the same forever loop, with setting the current encoder position first, setting the coordinates second, and then updating the past encoder position last.
note that I have no experience with block coding so I might be missing something with how the code ordering works.
You would need to add the calculated X and Y to the variable, not set it equal to them. Also, are you using two different encoders, since both x and y seem to have an encoder with the same name?
Instead of setting X1 to the math you did, set it to X1 = X1 + that math. Do the same for Y1. Also, odometry will not be that accurate without another perpendicular wheel to track if you get pushed sideways.
You don’t need the Y1 or X1 variable. In the Y part, it’s nearly right, but you should set it to be Y2 = Y2 + math, not Y1 + Math. You need to do the same for X, setting X2 to X2 + math, like you did for Y.
That defeats the whole purpose of vex and coding. The whole point of the competition is that you do it on your own and not somebody else. You’re basically asking for them to code it for you. There are plenty of threads on the forum for you to read and understand position tracking/odometry to code it yourself, including this one.
Thank you for everyones help. I am now trying to add another tracking wheel adjacent to the other for tracking side to side movement. How would I build this into my current code:
This is how you factor in the rotation of your new encoder. Since it’s perpendicular to the original encoder sin and cosin are inverted. (I had the code wrong my bad)