# Getting Started

## Wire up the ODrive

### Hardware Requirements

• An encoder, unless using sensorless mode.

• A >12V power supply or battery. Make sure you are within the voltage rating of your ODrive (58V for Pro, 50V for S1). Some advice on choosing a power supply can be found here.

### Connections

Warning

Make sure to avoid a ground loop! See the ground loop page for details.

1. Solder the motor phases onto the solder pads that are labelled A/B/C.

2. If the motor has a thermistor, connect it to THERMISTOR+ and THERMISTOR-.

3. Solder the power supply cables onto the solder pads that are labelled +/-.

4. If using an encoder, connect it to the corresponding I/O connector.

Note

Please see the full pinout page for important information about pin functionality and specifications.

### Safety & Power Up

Warning

Always think safety before powering up the ODrive if a motor is attached. Consider what might happen if the motor spins as soon as power is applied.

If possible, connect the power source first and then turn it on to avoid inrush current. If this can’t be avoided then a small spark is normal when plugging in the power connector, this is caused by the capacitors charging up. To avoid this issue we recommend using these anti spark connectors.

## Connecting to the ODrive

There are two methods for connecting your ODrive to a computer, a command line utility called odrivetool or our new web GUI. If you are using the GUI, select Connect new device in the top right corner and continue to Configure Power Supply, otherwise you will need to install odrivetool.

Note

You cannot use odrivetool and the GUI at the same time, if either say Could not claim interface make sure the other is closed and try again.

## Configure Power Supply

Use this configuration if you’re powering the ODrive from a power supply that plugs into the grid.

ODrive is a four-quadrant drive, so it regenerates braking energy into electrical energy when deccelerating. Most AC/DC power supplies do not accept reverse current, so there needs to be a method to dissipate the regenerated power. This can be done with a brake resistor on ODrives that have support for that, or otherwise with a regen clamp module.

Please adapt the ??? placeholders below. dc_bus_overvoltage_trip_level is the overvoltage fault level and should be set to a value that will protect it from overvoltage damage. For instance if your power supply outputs 24V a reasonable value is 30. dc_max_positive_current is the overcurrent fault level and should be set to a value that will protect your power source from overcurrent damage. dc_max_negative_current is the regenerated current fault level, it is a negative value.

odrv0.config.dc_bus_overvoltage_trip_level = ???
odrv0.config.dc_max_positive_current = ???
odrv0.config.dc_max_negative_current = -1

Additionally, on ODrive S1 if you have a brake resistor connected:

odrv0.config.brake_resistor0.resistance = ??? # resistance in Ohms
odrv0.config.brake_resistor0.enable = True
odrv0.save_configuration()

## Motor Configuration

We only list configurations for the most commonly used motors here. If you’re using a different motor, you can use these scenarios as reference and read up on the documentation of the settings to adapt them for your motor.

odrv0.axis0.config.motor.motor_type = MotorType.HIGH_CURRENT
odrv0.axis0.config.motor.pole_pairs = 7
odrv0.axis0.config.motor.torque_constant = 8.27 / 270
odrv0.axis0.requested_state = AxisState.MOTOR_CALIBRATION
# [wait for end of motor beep]
odrv0.save_configuration()

# Thermistor config is not currently supported in the GUI
set_motor_thermistor_coeffs(odrv0.axis0, Rload=1000, R_25=10000, Beta=3435, Tmin=-10, Tmax=150, thermistor_bottom=True)
# thermistor must be connected
odrv0.axis0.motor_thermistor.config.enabled = True
odrv0.save_configuration()

Warning

If you change the motor, make sure to re-run the motor calibration.

### Setting the Limits

#### Current limit

odrv0.axis0.config.motor.current_soft_max = 10 # [A] (adapt this to your motor)
odrv0.axis0.config.motor.current_hard_max = 18 # [A] (should be more than soft max)

It is recommended to set the soft max to something quite weak to start with, but strong enough to overcome friction in your system with a decent margin. Once you have built confidence in the stability of the control and strength of your mechanical setup, you can increase these. For high current motors you need to turn this up to get high performance, and for low current motors such as the BotWheel you need to use something that’s lower than the examples shown above.

The recommended maximum for current_soft_max is the continuous current rating of your motor if you are not using motor thermistor temperature feedback, and the peak current rating of your motor if you are using it. The hard max is a fault trip level and should be set to a level above the soft max. The appropriate level is a tradeoff between getting nuisance faults especially during high accelerations, and ability to catch unstable current control situations. The recommended maximum is the current your motor can handle for 50ms.

Note

The motor current and the current drawn from the power supply is not the same in general. You should not look at the power supply current to see what is going on with the motor current.

#### Velocity limit

odrv0.axis0.controller.config.vel_limit = 2 # [turn/s]


The motor will be limited to this speed. Again the default value is quite slow.

#### Temperature limits

odrv0.axis0.motor_thermistor.config.temp_limit_lower = 100 # °C (adapt this to your motor)
odrv0.axis0.motor_thermistor.config.temp_limit_upper = 120 # °C (adapt this to your motor)

## Encoder Configuration

Note

The rotor must be allowed to rotate without any biased load during encoder calibration. That means mass and weak friction loads are fine, but gravity or spring loads are not okay. Heavier loads are not advised, it is recommended that you lift any wheeled robot off the ground.

The following commands assume you have the encoder connected to the Motor I/O connector.

Connecting the A,B phases is mandatory, the Z (index pulse) is optional.

odrv0.inc_encoder0.config.cpr = 8192
odrv0.inc_encoder0.config.enabled = True
odrv0.axis0.config.commutation_encoder = EncoderId.INC_ENCODER0
odrv0.save_configuration()
# [wait for ODrive to reboot]
odrv0.axis0.requested_state = AxisState.ENCODER_OFFSET_CALIBRATION
# [wait for motor to stop]


After each subsequent reboot you need to re-run odrv0.axis0.requested_state = AxisState.ENCODER_OFFSET_CALIBRATION before you can activate position/velocity control.

Warning

If the encoder setup changes at all, make sure to re-run the encoder offset calibration.

### Viewing Encoder Feedback

Position and velocity feedback from the load_encoder can be found in the Mapper pos_vel_mapper by entering

odrv0.axis0.pos_vel_mapper.pos_rel
# or
odrv0.axis0.pos_vel_mapper.vel


Similarly, feedback from the commutation_encoder can be found in the Mapper commutation_mapper.

What is a Mapper?

A Mapper converts from one rotational/linear space to another rotational/linear space. For example, from an encoder’s circular output onto the user’s axis linear space, or the motor’s electrical phase circular space.

## Status LED

The current status of the ODrive can be observed by the color the LED:

• blue/teal: The ODrive is idle. It will not move, and has no errors.

• green: The ODrive is active and running.

• red: An error has occured and the ODrive is disabled. Please refer to the troublshooting page for more information.

## Position Control

Warning

Make sure you have a good mechanical connection between the encoder and the motor, slip can cause disastrous oscillations or runaway.

1. Enter closed loop control mode by setting odrv0.axis0.requested_state to AxisState.CLOSED_LOOP_CONTROL.

From now on the ODrive will try to hold the motor’s position. If you try to turn it by hand, it will fight you gently. That is unless you bump up odrv0.axis0.config.motor.current_soft_max, in which case it will fight you more fiercely. If the motor begins to vibrate either immediately or after being disturbed you will need to lower the controller gains.

2. Send the motor a new position setpoint by setting odrv0.axis0.controller.input_pos to 1.

The units are in turns.

3. At this point you will probably want to properly tune the motor controller in order to maximize system performance.

## Other Control Modes

The default control mode is unfiltered position control in the absolute encoder reference frame. You may wish to use a controlled trajectory instead. Or you may wish to control position in a circular frame to allow continuous rotation forever without growing the numeric value of the setpoint too large.

You may also wish to control velocity (directly or with a ramping filter). You can also directly control the current of the motor, which is proportional to torque.

### Filtered Position Control

Asking the ODrive controller to go as hard as it can to raw setpoints may result in jerky movement. Even if you are using a planned trajectory generated from an external source, if that is sent at a modest frequency, the ODrive may chase each stair in the incoming staircase in a jerky way. In this case, a good starting point for tuning the filter bandwidth is to set it to one half of your setpoint command rate.

You can use the second order position filter in these cases.

odrv0.axis0.controller.config.input_filter_bandwidth = 2.0 # Set the filter bandwidth [1/s]
odrv0.axis0.controller.config.input_mode = InputMode.POS_FILTER # Activate the setpoint filter
odrv0.axis0.controller.input_pos = 1 # control the position [turns]


Step response of a 1000 to 0 position input with a filter bandwidth of 1.0 [/sec].

### Trajectory Control

See the :usage section for details. This mode lets you smoothly accelerate, coast, and decelerate the axis from one position to another. With raw position control, the controller simply tries to go to the setpoint as quickly as possible. Using a trajectory lets you tune the feedback gains more aggressively to reject disturbance, while keeping smooth motion.

#### Parameters

odrv0.axis0.trap_traj.config.vel_limit = <Float>

odrv0.axis0.trap_traj.config.accel_limit = <Float>

odrv0.axis0.trap_traj.config.decel_limit = <Float>

odrv0.axis0.controller.config.inertia = <Float>

• vel_limit is the maximum planned trajectory speed. This sets your coasting speed.

• accel_limit is the maximum acceleration in turns / sec^2

• decel_limit is the maximum deceleration in turns / sec^2

• controller.config.inertia is a value which correlates acceleration (in turns / sec^2) and motor torque. It is 0 by default. It is optional, but can improve response of your system if correctly tuned. Keep in mind this will need to change with the load / mass of your system.

Note

All values should be strictly positive (>= 0).

Keep in mind that you must still set your safety limits as before. It is recommended you set these a little higher ( > 10%) than the planner values, to give the controller enough control authority.

odrv0.axis0.config.motor.current_soft_max = <Float>

odrv0.axis0.controller.config.vel_limit = <Float>


#### Usage

Make sure you are in position control mode. To activate the trajectory module, set the input mode to trajectory:

odrv0.axis0.controller.config.input_mode = InputMode.TRAP_TRAJ


Simply send a position command to execute the move:

odrv0.axis0.controller.input_pos = <Float>


Use the move_incremental function to move to a relative position.

odrv0.axis0.controller.move_incremental(pos_increment, from_goal_point)


To set the goal relative to the current actual position, use from_goal_point = False To set the goal relative to the previous destination, use from_goal_point = True

You can also execute a move with the appropriate ascii command.

### Circular Position Control

To enable Circular position control, set

odrv0.axis0.controller.config.circular_setpoints = True


This mode is useful for continuous incremental position movement. For example a robot rolling indefinitely, or an extruder motor or conveyor belt moving with controlled increments indefinitely. In the regular position mode, the input_pos would grow to a very large value and would lose precision due to floating point rounding.

In this mode, the controller will try to track the position within only one turn of the motor. Specifically, input_pos is expected in the range [0, 1). If the input_pos is incremented to outside this range (say via step/dir input), it is automatically wrapped around into the correct value. Note that in this mode encoder.pos_circular is used for feedback instead of encoder.pos_estimate.

If you try to increment the axis with a large step in one go that exceeds 1 turn, the motor will go to the same angle around the wrong way. This is also the case if there is a large disturbance. If you have an application where you would like to handle larger steps, you can use a larger circular range. Set

odrv0.axis0.controller.config.circular_setpoints_range = <N>


Choose N to give you an appropriate circular space for your application.

### Velocity Control

Set the control mode

odrv0.axis0.controller.config.control_mode = ControlMode.VELOCITY_CONTROL


You can now control the velocity [turn/s] with

odrv0.axis0.controller.input_vel = 1


### Ramped Velocity Control

Set the control mode

odrv0.axis0.controller.config.control_mode = ControlMode.VELOCITY_CONTROL


Set the velocity ramp rate (acceleration in turn/s^2):

odrv0.axis0.controller.config.vel_ramp_rate = 0.5


Activate the ramped velocity mode:

odrv0.axis0.controller.config.input_mode = InputMode.VEL_RAMP


You can now control the velocity (turn/s) with

odrv0.axis0.controller.input_vel = 1


### Torque Control

Set the control mode

odrv0.axis0.controller.config.control_mode = ControlMode.TORQUE_CONTROL


Set the torque constant, e.g.:

# Approximately 8.23 / Kv where Kv is in the units [rpm / V]
odrv0.axis0.config.motor.torque_constant = 8.23 / 150


You can now control the torque (Nm) with e.g.

odrv0.axis0.controller.input_torque = 0.1


Note

For safety reasons, the torque mode velocity limiter is enabled by default. This works by reducing the torque of the motor according to vel_limit and vel_gain, as shown below. Please note that with the default settings, torque will limited even at 0 rpm.

The torque mode velocity limiter can be completely disabled by setting:

odrv0.axis0.controller.enable_torque_mode_vel_limit = False


## What’s Next?

You can now:

• Properly tune the motor controller to unlock the full potential of the ODrive.

• See what other commands and parameters are available, in order to better control the ODrive.

• Control the ODrive from your own program or hook it up to an existing system through one of it’s interfaces.

• See how you can improve the behavior during the startup procedure.

If you have any issues or any questions please get in touch. The ODrive Community warmly welcomes you.