How can I decelerate my robot in autonomous according to the encoder? ex: the robot slows down as it gets closer to its target distance

I’d like our robot to slow down as it gets close to its target distance on the field by reading the encoders and basing its speed around them. I don’t want it to start of slowing down, but waiting until about 100 or so clicks away from the target so it doesn’t knock over the cap or screw up alignment as it gets closer, but still maintain full speed until that point. How could I do that?

One option would be to use a P loop, but since you said that you don’t want it to gradually slow down, that might not be the best choice. The other option is to have a variable that controls speed. In the loop causing the movement, you could constantly be checking how far you are from your target. Once the distance from your target is small enough, simply change that variable to a slower speed.

If you’re not sure of how to do these things, mention me and I’ll post some sample code.

Here are some really useful tutorials I have found.

the second video is a playlist i forgot to mention that

Thank you for the videos, but we’re mostly focused on V5s in particular because we’re new to its language.

Those videos are simply concepts. You could easily program that functionality using any of the V5 programming languages.

Can you have voids and integers in the V5 coding?

I would be shocked if you couldn’t, if you can’t then it’s not much of a coding language.

Since all of the languages support full function abilities, the answer is yes. Which language are you using though. That’ll help us answer questions more specifically to what you need.

We’re using the Vex C++

The main thing we’re trying to get is constantly get the encoder value. But I’ve been told that the encoder is its own function or something like that (I’m not fluent in Vex C++) so while the robot is driving based off the encoder, we can’t access the encoder.

Do you mean that it won’t update the values until the motor stops moving? I’m not sure I fully understand.

I think I was told that you couldn’t access the rotations until the goal rotations had been achieved. Since we can only do one function at a time, we have to wait until the rotations have finished before starting something else. This is what I’d like to be proven wrong on

Look up multitasking for vex c++. There are plenty of tutorials on the forum.

The command Motor.rotations()is a function that simply just returns the value of the encoder, no matter what it’s doing. Your problem is probably that the function you are using to move rotations is Motor.rotateFor(). This is a blocking function, which means the code will not proceed until the function is done. You can create a separate thread to run the encoder tracking, like this:

int encoderRotation;
void  trackRotation(){
   while(true){
       encoderRotation = Motor.rotation(vex::rotationUnits::deg);
       vex::task::sleep(20);
   }

thread t1(  trackRotation );
1 Like

Take a look at the logic of this example of motion profiling that I wrote in Robot Mesh Studio. I think the only thing that would have to change to use it in VCS is replacing the call to sleep in main with a VCS equivalent. This code also handles slowly starting from a stop as slowly coming to a stop.

Multiply a fraction (whatever works out) by the difference between your position and your target position

or use motor.stop(brakeType::coast) to slow it down.