Skip to content

[T ELEC 0] ODrive

papara78 edited this page Apr 9, 2019 · 36 revisions

ODrive

Objective:

We chose to use brushless motors that are cheap and powerful but it is difficult to control them. That's why we need an ODrive which is a high performance motor control. It can also control the encoders.

Requirements:

  • We used the ODrive Version 3.5 48V. You can visit the official website for more information about the board ans its features.
  • You will also need a Stm32 to communicate with the ODrive.
  • And a CAN transceiver: the MCP2551.

ODrive

Steps:

Install ODrive Tool

The ODrive Tool is the accompanying PC program for the ODrive. Its main purpose is to provide an interactive shell to control the device manually, as well as some supporting functions like firmware update.

We followed the instructions on the official ODrive documentation that you can find here. Make sure that you follow the instructions correctly. The problem we encountered is that we had several python version installed. You need to only have the version specified.

Getting started

Follow the Getting Started tutorial of the official webpage. Make sure to configure the motor with the correct values of your motor (pole pairs) that you should find in the motor's datasheet.

After that, follow the encoder calibration tutorial depending or whether your encoders have an index signal or not.

CAN module

We chose to use CAN to communicate with the ODrive. The stm32 will send orders to the ODrive to controll the motors.

As ODrive is in opensource, most of the features are developed by the community. We used a firmware that implemented a simple CAN protocol. You can find the project here.

Flash the firmware that implemented the CAN module

Once you downloaded the project, you have to generate the .elf file to flash it on the ODrive. To do that, simply type make in the folder that contains the Makefile. We encountered several problems for this task, the main one is that we had to install tup and libfuse-dev. To install tup, you can check this tutorial.

And to make things easier we bought a ST-link to flash the firmware. Just connect it to the ODrive and the computer and follow the instructions of the official documentation.

Setup the electrical circuit

The circuit to build a CAN transceiver circuit using an MCP2551 chip is shown below. Connect the Tx and Rx pins to the ones corresponding to your stm32. MCP2551 pinout breadboard circuit

Communication between ODrive and stm32 with CAN

Before going further you should read this page that explains how the CAN protocol is impletemented by the creator. Make sure to understand how we compute the can NodeID and the tables that list the command we can give and their IDs.

You can download the code that deals with the communication between the ODrive and the stm32. To understand this part of the code we'll explain a simple code that we used to send orders from our stm32. Take a code example from mbed here. You will need to sign up if you didn't.

You should create a CANMessage: CANMessage (int _id, const char *_data, char _len)

Where id is the message id, data is a pointer to your payload and len the length of data in bytes.

The tricky part is the payload we send.

For example if you want to send the order Move To Pos 1000 knowing that the node id is 35, the payload should be as followed:
char payload[4];

payload[0]=(uint32_t)1000;

payload[1]=(uint32_t)1000>> 8;

payload[2]=(uint32_t)1000>> 16;

payload[3]=(uint32_t)1000>> 24;

And the creation of the CAN message: CANMessage(0x23B,payload,4)

Conclusion:

When we worked on the project the CAN feature was still in development and there was no UART communication too. Make sure to check is there is new features or not that can help to communicate with the ODrive before implementing your solution.

Tips:

The firmware version we used may not be the latest one since the project is still in development check the git on the references to download the latest version.

References:

https://discourse.odriverobotics.com/t/can-interface-available-for-testing/1448 http://www.learningaboutelectronics.com/Articles/MCP2551-CAN-transceiver-circuit.php https://ide.mbed.com/compiler

Clone this wiki locally