Njord Project

Build an awesome drone from scratch

Motors

The last time we introduced the different components that we have chosen to construct our drone. For this article we have received some pieces. Before assembling everything, we thought it could be more convenient to write the different libraries. The purpose of this article is to present the library that we have written in order to control the motors.

Library

As you can see the photo below, those motors are really tiny. Then, they can't produce a huge torque. However, if we are right it should be sufficient.

Moteur_BCC01B

Certainly, this component is the easier to take in the hand. You have just to supply the motor to get it active. Therefore, the library that we offer is really simple. First, take a look to the declaration:


#ifndef Bccm01b_h
#define Bccm01b_h

#include "Arduino.h"
#include <stdint.h>

//Class representing one motor
class Bccm01b {
	public:
		Bccm01b ( uint8_t pin ); //Constructor
		int controlSpeed ( int value ); //Setter speed
		int reportSpeed (); //Getter speed
		const uint8_t getPin (); //Getter pin
	private:
		const uint8_t _pin;
		int _value; //Speed
};

#endif
					

One motor is represented by an instance of Bccm01b class (which is the model of our motor). Composition of this class is pretty simple. One motor is only composed by a pin and a value (directly linked to the speed of rotation).

Beyond the constructor and the getters which are not special, we will focus only on the function which allow us to modify the speed. Motors are connected to PWM pins, then values can only vary between 0 and 255. Therefore, we have to check that the value passed as argument is in this range. If it not, then we return an error to the user.

Of course you can download this library on our GitHub.

Demonstration

To sum up this article, this is a video presenting a test of our library. This test is settle to control one motor and increase its speed, until it reaches its maximal value (255). Then, we decrease this value until the motor stop (0). (This test is present in the same repository as the library).

A forthcoming article will be dedicated to the manipulation of radio transmitter/receiver component.