Jetson Xavier motor control (Solved)

Hi,

I have done a lot of research into how to program a motor from the Jetson but from the pieces I have found online I have a few questions.

I am starting a drone project and want to understand the software and hardware requirements to program a motor. From what I understand I need a brushless motor, linked to an electronic speed controller. This is then programmed through Python and ROS.

Questions:

  1. Can I connect the speed controller directly to the Jetson Xavier or do I require some intermediate hardware? Is there a special kind of ESC that I need or will something like this suffice? (https://hobbyking.com/en_us/hobby-king-20a-esc-3a-ubec.html?___store=en_us)
  2. I believe that ROS is the best way to 'speak' to the controller. I have done some research into ROS nodes but wonder how do I specify the hardware source of a specified node?

thank you in advance

Depending on the application, you can use brushed, brushless, SAC, IPM, or linear motors. Brushless are great for drone rotor power, so you’re not wrong there, but the motor choice depends on the application.

The motor controller is the part that receives control signals from somewhere, plus main power, and transfers that into the power signals needed to make the motor “go” the way you want. In many instances, you also have some kind of sensor on the motor, or on the output of whatever the motor is driving, so that the controller can match a desired speed, position, or torque. (This is typically referred to as “closed loop servo control.”)

The name “Electronic Speed Control” is a hobby term, used for hobby radio controlled airplanes, cars, and now drones. Typically, an ESC receives pulse-width input (1000 us pulse means “minimum,” 2000 us pulse means “maximum” typically somewhere between 3 and 16 millisecond period between each pulse.
I have not seen documentation for the Xavier mention any programmable controller hardware that can generate a high-accuracy pulse train as needed to control those ESC devices. Thus, you have two choices:

  1. Use an intermediate controller that speaks USB, UART, I2C, CAN, or some other protocol that the Xavier does well, and converts instructions over this protocol to the PWM pulses needed by a typical ESC. You could use an Arduino or a Teensy 3.2 (my favorite) microcontroller to speak to the Jetson on one side and the controller on the other. There are tons of other options (Pololu Mini Maestro, Adafruit I2C Servo PWM board, and so on.)

  2. Use a motor controller that can speak one of those protocols. Most common in hobby drone circles seem to be UART or I2C based controllers, but I think some of them can do CAN, too. I think some of the higher-end ones on HobbyKing may be able to do this; you’ll need to do some searching to find a good model and source.

Btw, the hobby king controllers you’re pointing at are limited at 20A, and typically overheat if you keep drawing that current for any amount of time (so they should be run at a lower typical load.) This may not be enough to drive the propellers/motors that will lift a drone that mounts a 700 gram controller like the Jetson, in addition to all the other weight (motors, battery, frame, etc.)

Once you have a motor matched to the application, and a controller matched to the motor, and a protocol that the Jetson can emit, you need to write code on the Jetson to emit the appropriate control signals over that protocol / hardware device. You can do this in any language, using any library, or no library at all other than the Linux kernel/device driver interface.

Yes, you can use ROS as a library. Yes, you can write code in Python. Whether that’s the right choice for you, depends entirely on what you already know how to do do, and what you want to achieve.

For example, for drone flight, you will need to use an IMU of some sort. Typically you will poll this very quickly, at the same rate as your motor control. The normal Linux kernel on the Jetson is not great at real-time work, so you’ll probably want some smaller microcontroller for the IMU and motor control bit, rather than trying to use the Jetson for all of that I/O and reactive work. You can use an existing “pilot” controller for this, or you can build your own on top of a microcontroller (like the Teensy.) Again, entirely depends on what you want to achieve.

1 Like

@snarky Thank you very much for putting the time into such a detailed answer, it is incredibly helpful. If you are ever in London then I owe you a beer.

Could I ask one question about the Teensy (or such) microcontroller. Am I right in saying that this would control the basic actions of the drone, i.e. move left, move right, hover, etc… and the Jetson would ask as the instruction engine turning these simple actions into something meaningful?

Thank you

1 Like

I the words I like to use, the Jetson would still be in charge of “move left;” the controller then takes those control signals and turns them into actual motor power output control.
The drone control loop is, simplified, something like:

  1. Figure out the current attitude and velocity of the drone (this is the “poll the IMU” part)
  2. Compare to desired attitude and velocity (control inputs from remote, Jetson, or something else)
  3. Apply motor power to each of the four different motors to compensate for any discrepancy between 1) and 2)

The trick is that you have four motors, which aren’t entirely indepdendent, because they’re all in a single plane, and you have nine degrees of freedom (three rotation, three position, and three velocity) so the control loop needs to be programmed to do the best possible thing compared to what it needs. For example, if you want to tilt sideways, doing that will change lift and will start moving that direction, which will affect both position and velocity. Doing this control loop 200-1000 times a second is what microcontrollers are great at.

No immediate plans for London, but when that changes, be prepared :-)

1 Like

we use this Grove - I2C Motor Driver with L298 - Seeed Studio