Customizing Mechanical Brake Operation

I’m working on a project that has a motor with a mechanical brake that only actuates occasionally. The system is under load at all times, and the brake is there to hold things in place when not moving. The normal operation of the mechanical brake built into ODrive Pro doesn’t really work for this application, as the brake would always be disengaged when the system is powered, and the motor would be left to hold position when not moving instead of the brake.

I’d like to have the brake operate something like this:

odrv.axis0.mechanical_brake.config.gpio_num = 0
odrv.config.gpio0_mode = GPIO_MODE_MECH_BRAKE

if abs(odrv.axis0.controller.input_pos - odrv.axis0.pos_est) < 0.2:
    odrv.axis0.mechanical_brake.engage()
else: 
    odrv.axis0.mechanical_brake.release()

… but I can’t figure out how to get the ODrive to do this. It doesn’t necessarily have to be controlled via the .mechanical_brake. logic.

Any means by which I could get a GPIO pin to output high when the error between the requested and actual position is greater than a certain value would be greatly appreciated.

Hi! Sorry for the delay in my response. This isn’t something we have support for quite yet – down the line when we have user scripting support this would be much more straightforward. I think my recommended course of action would be to use whatever external microcontroller/motion controller is connected to handle this logic – are you using an Arduino, Raspberry Pi, etc?

Note that engaging the brake while in closed loop control will definitely cause integrator windup, and even if you set the integrator limit to zero after engaging the brake, you’ll still have some torque being output by the pos/vel terms. You’d likely want to set the motor torque limits to zero once the brake is engaged, and then set it back to nominal after disengaging.

Thanks for the response.

Unfortunately, I’m using a relatively “dumb” RC controller to provide the control signals. I’d hoped to leverage some of the control logic in the ODrive for the one axis in the system that isn’t native to RC-Servo style control.

I plan on getting a Feather to handle this now. It’ll request feedback from the ODrive, then command brake operation and change ODrive settings accordingly.

Thanks for the control limits suggestion, I’m sure it’ll be very helpful as I move from bench testing to system operation. So far on the bench with the brake manually controlled, the motor hasn’t bound up, but it is definitely on the edge of trying to, and almost certainly would have with loads applied.

Gotcha - totally understood. ODrive is definitely made with the assumption of having a “smart” controller handling any high level logic, and the ODrive focusing on the motor control – PWM was sort of a side thing from popular request :slight_smile: in the future once we have user scripting support, things like this will be a lot easier – I’m looking forward to that!