This week I focused on programming the brushless motors that I am using for my final project.

My final project is an RC Boat, that will be powered by fans.

The motors I have come as part of an ESC + Motor kit, shown below.

Bear_CAD

Bear_CAD

The way these motors + their ESC's work is by PWM control. Each motor has a duty cycle of 20 ms, for which the lowest speed is sending a pulse for 1ms or lower, and max power is sending a pulse for 2ms. The speed of the motor scales linearly between 1ms and 2ms. This is explained by the diagram, which shoes the difference between a narrow pulse leading to lower voltage and therefore current, and the opposite for a wider pulse.

The motors are connected to an ESC for facile control.

In my code I decided to implement a very simple control system to begin. In addition to the PWM Control implemented, I decided to have 3 modes: up, left, right.

Up means going straight, requiring equal thrust from both motors (and thus identical pwm). Turning left means the left motor goes slower than the right, and vice versa for turning right.

I also switched to C++ from python, and learnt the basics over the weekend! This made sense as there is dramatically more documentation C/C++ and a lot more available libraries, that will likely simplify the implementation and processing of other components e.g. Compass, GPS, NRF24L01.

I discovered that initialization was important for ESCs. The method for the ESCs I was using is to first send a '0' command, which is the minimum pwm value, i.e. 1 ms pulse. Then send the max of 2 ms. From then you can send any value between 1 and 2 ms pulses. The motor will beep twice once it's fully initialized, as was discovered through reading the documentation. Before it's initialized, it will just beep consistently without stopping.

My basic code involves sending commands 'u', 'l', and 'r' through serial. I've included the file here .

The motors are shown working in the video below! I first switch them on on 'u' mode, then switch to 'l' and 'r' mode. I did this week concurrently with networking/comms, so they're controlled wirelessly with NRF24L01 modules.

I made sure to bolt the motors down to a piece of wood, and then clamp said piece of wood, as they are a safety hazard. I'll be printing a safety guard for these motors too soon.

Backup video link is here