ReRun, with no Velocity

Hey guys, I’ve been working on rerun code, but am not able to get velocity control. If anyone could help me with such code it would be appreciated.

Velocity control? How do you mean? If you’re looking just to calculate velocity, that’s easy enough to do (assuming encoders).

int velocity;
int lastPosition;

task velocityCalc(){
velocity = lastPosition - currentPosition;
lastPosition = currentPosition;

This spits out a velocity that’s ticks/10 milliseconds (kind of a strange unit, but velocity nonetheless)

If you’re looking for a PID control loop or something, that’s also quite easy; just the same as a position control loop only using velocity instead of position.

@mwang17 Thanks for the sample, much appreciated! However, is this code using IME or OSE?

From the code,


is a global that the

task velocityCalc() 

assumes is updated elsewhere. That update could be based on IME, OSE, ultrasonic rangefinder, dead reckoning, differential GPS, counted knots, sextant readings, bread crumbs, or whatever else you might imagine. That’s up to you. Since you’re on a VEX forum, though, the first 3 in that list are likely to be what you want.

Is there some method you’d prefer? If you have something installed already, let the forum know, and they’ll help.

cough Don’t use robot outputs, use inputs. cough

I have a ReRun program (flawless) as well.

@Aditya Diwakar How would I go about doing that? Could you provide me with an example?

Sadly I cannot.

However, I will give you a hint - Use PROS and use frames.

What are “frames”?

There has been quite a discussion on this before, you can find my old velocity based rerun (and a lot of relevant discussion about rerun) here -

@mwang17 IDK if this is a necro, if it is, sorry. I’m sorry, but I need a bit more help with getting the velocity at any given time.

What kind of help do you need? Do you want to post your code?

@OverlyOptimisticProgramer Basically, I have a way to get the sensor data and everything, the only thing we are missing is velocity. We made a crappy attempt to give the motors a constant value of 127.

Frames mean that at every tick of your code evaluation (in your main while loop), record the state of every button press to record. Then, to play them back, simply go through each frame. This proves to be more effective than measuring output

Are you wanting to find velocity or get to a velocity? I can help you with either and if you don’t want to wait, the first is lastsensorvalue - currentsensorvalue and the second use a take back half or pid velocity control loop…

@OverlyOptimisticProgramer The problem is that I don’t understand how to write either of those things.

This is all in robotC but it can be transferred into pros or whatever easily. This code is assuming you have a standard tank drive


Copy the debugger stream of that into your autonomous and have these functions defined:

Void leftPID(int target)
Motor[leftWheel]=Kp*(target-sensorValue[leftWheelEncoder] +leftintegral;
sensorValue[leftWheelEncoder] =0;
Void rightPID(int target)
Motor[rightWheel]=Kp*(target-sensorValue[rightWheelEncoder] +rightintegral;
sensorValue[rightWheelEncoder] =0;

This is only a PI loop but I don’t like the D part and it should be fine. The biggest potential problem is when switching targets, the integral doesn’t reset which is only a problem if you rapidly switch directions. This code is not tested and probably has a couple of bugs. Encoders can be switched with potentiometers, sonar, etc.

@OverlyOptimisticProgramer Thank you very much! I’ll be debugging it and most likely repost if I’m successful!

I made my ReRun code public today. It isn’t the most recent version, but it does use velocity. I’m not sure how useful it will be in the new season because of how accurate you need to be. I’ll be sure to mess around with rerun once we get our field.

Thanks @Unionjackjz1, reply in discord DM pls.

What does the function TankWithoutTrueSpeed do in the rerun.
EDIT: Can you help me understand the code a bit better, I understand most of it but I’m not sure of what the auton function does.