JM9 XRCU Board 0.1.3a
Libraries API Reference
Loading...
Searching...
No Matches
Motors.h
Go to the documentation of this file.
1
8
9#ifndef MOTORS_H
10#define MOTORS_H
11
12#include <Arduino.h>
13
14#include <Supported_actuator.h>
15
20class Mtr : public Supported_actuator {
21 private:
22 // the PWM channel of the motor
23 const uint32_t pwm_ch;
24 // the PWM pin of the motor port
25 const uint32_t pwm_pin;
26 // the direction pin of the motor port
27 const uint32_t dir_pin;
28
29 // whether the motor reverses spinning direction
30 bool reverse_dir;
31 // the apparent speed of the motor as seen by the programmer
32 int16_t apparent_spd;
33
39 void set_raw_spd (int16_t spd);
40
44 friend void XRCU_menu ();
45
46 public:
54 Mtr (const uint32_t pwm_ch, const uint32_t pwm_pin, const uint32_t dir_pin);
55
59 void begin ();
60
64 void end ();
65
71 bool get_reverse_flag ();
72
78 void set_reverse_flag (bool reverse);
79
86 int16_t set_spd (int16_t spd);
87
94 int16_t operator= (const int16_t spd);
95
102 int16_t operator+= (const int16_t spd_inc);
103
110 int16_t operator-= (const int16_t spd_dec);
111
117 int16_t operator++ ();
118
124 int16_t operator-- ();
125
131 int16_t get_spd ();
132
138 operator int16_t ();
139};
140
146extern Mtr mtrs [4];
147
153extern Mtr &mtr1;
154
160extern Mtr &mtr2;
161
167extern Mtr &mtr3;
168
174extern Mtr &mtr4;
175
176#endif // #ifndef MOTORS_H
Motor Driver for XRCU.
Definition Motors.h:20
void end()
Deactivates the motor and release the occupied resources.
Definition Motors.cpp:62
friend void XRCU_menu()
int16_t operator-=(const int16_t spd_dec)
Decreases this motor speed by spd_dec.
Definition Motors.cpp:169
int16_t get_spd()
Gets the motor speed.
Definition Motors.cpp:180
int16_t operator=(const int16_t spd)
Sets the motor to spin at a new speed, and return its motor speed after setting.
Definition Motors.cpp:161
int16_t operator--()
Decreases this motor speed by 1.
Definition Motors.cpp:176
Mtr(const uint32_t pwm_ch, const uint32_t pwm_pin, const uint32_t dir_pin)
Constructor for Mtr objects.
Definition Motors.cpp:26
int16_t operator++()
Increases this motor speed by 1.
Definition Motors.cpp:173
bool get_reverse_flag()
Gets whether the motor spinning direction is reversed when driving to the motor.
Definition Motors.cpp:67
void set_reverse_flag(bool reverse)
Sets whether the motor spinning direction is reversed when driving to the motor.
Definition Motors.cpp:71
int16_t set_spd(int16_t spd)
Sets the motor to spin at a new speed, and return its motor speed after setting.
Definition Motors.cpp:140
void begin()
Activates the motor.
Definition Motors.cpp:36
int16_t operator+=(const int16_t spd_inc)
Increases this motor speed by spd_inc.
Definition Motors.cpp:165
Supported_actuator()
Creates an object of a supported actuator.
Definition Supported_actuator.h:23