# Braking and holding

So i am trying to brake and hold the robot on the platform. i have heard that people are using PID to hold it, and i know what is it, but my mathematics level is too low to comprehend and use it. Does anyone know a way to hold the robot without using PID?

Are you using Cortex or V5? V5 has a â€śholdâ€ť function in its brakeType commands with built-in PID.
As for Cortex, there are most definitely PID tutorials out there that are really helpful. I donâ€™t have any off the top of my head, but I know Iâ€™ve seen them.

But holding the wheels still isnâ€™t the only way to brake a robot. You could also theoretically have a deployable pad that presses against the platform that acts as a brake.

Im using V5 and PROS. I couldnâ€™t modify anything with the robot. How to i use the hold function in pros?

As stated, V5 has built in PID to control the hold function. Iâ€™m not exactly sure how to call it, as I donâ€™t use PROS. Weâ€™d have to get a PROfessional in here to help with that much. (Edit: Yes, I stole that pun.)

2 Likes

ok i will search the pros documentationâ€¦ Thanks

so i use this code and it actually works.

holdMove = master.get_digital(DIGITAL_Y);
if (holdMove ==true){
leftFront.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
leftRear.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
rightFront.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
rightRear.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
}else{
leftFront.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
leftRear.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
rightFront.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
rightRear.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
}

(this is in a the infinite loop of the op control)
The problem now is that the force is not strong enough or i donâ€™t know what.
it successfully brakes the wheels after it is stopped.
But, when i turn the wheels, it gives me some resistant force but it doesnâ€™t practically move back to the original position.
What is happening? do i have to edit the pid parameters and how do i do that?

Once again, I donâ€™t use PROS, nor do I know as much about coding as others, but I have another idea.
What if you set up a function ot take the current built-in encoder value, and then have a loop telling the motor to go to that value? It might register any change, and fight against it. (?)
But thereâ€™s probably an easier way to do that. Maybe itâ€™s built in and I just donâ€™t know about it.

Sorry I couldnâ€™t be of more help.

@Eden Check out This thread and maybe itâ€™ll help. It seems to be exactly what youâ€™re looking for. If not, maybe @sazrocks can help here.

Thanks alot@Got_a_Screw_Loose

1 Like

This is exactly what setting the brake type to HOLD does when the motor is commanded to stop.

Yes. I knew htat. But what I didnâ€™t know was why it might not have been working, so I decided to come up with a workaround to do it manually. Of course, itâ€™s not needed because the issue was resolved.

1 Like

What if I want to achieve open-loop control and closed-loop control switching?

1 Like

leftFront.move_velocity(0);
leftRear.move_velocity(0);
rightFront.move_velocity(0);
rightRear.move_velocity(0);

it stills stays the same.
the proble is still that it will only supply a low resistant when i push it and is not capable to move back to its original positition.
also, it(the small resistant force) cannot be activated when the motor are not moving

for your information, the small resistant disappears after i release the button

It disappears because the code no longer reads the button as pressed, and sets the brake type back to normal. There are ways to make a toggle button, though. Iâ€™m not sure what the best way to go about doing it in PROS would be.
Personally, I would be fine with just holding the button. But I can see the superiority of the toggle button.

yes of course i know how to toggle a bool value with a button
that is not the problem

Sorry, I read this as a secondary problem. I donâ€™t really think Iâ€™ll be much help on the bigger problem, though. I tried. Sorry I donâ€™t know absolutely everything.

1 Like

Ok guys i actually worked out way to do it.
here is the code:

void holdService(void* param){
while(true){
if (holdMove){
short absLF = leftFront.get_position();
short absLR = leftRear.get_position();
short absRF = rightFront.get_position();
short absRR = rightRear.get_position();
while(holdMove){
leftFront = absLF - leftFront.get_position();
leftRear = absLR - leftRear.get_position();
rightFront = absRF - rightFront.get_position();
rightRear = absRR - rightRear.get_position();
pros::delay(25);
}
}
pros::delay(25);
}
}

(this is a task, it continues running in parallel of other infinite loops)

void opcontrol() {
bla bla bla code
if(abs(master.get_analog(ANALOG_LEFT_Y))<2 &&abs(master.get_analog(ANALOG_LEFT_X))<2 &&abs(master.get_analog(ANALOG_RIGHT_X))<2){
holdMove = master.get_digital(DIGITAL_Y);
}else{
holdMove = false;
}
}

this is to help other people on holding the robot. if you have any questions, you could ask me

1 Like

btw this is using only p (proportional) in PID

1 Like