#include <Dshot.h>
Definition at line 13 of file Dshot.h.
◆ Dshot()
Dshot::Dshot |
( |
uint32_t |
speed_hz = 150000 , |
|
|
bool |
bidirectional = false |
|
) |
| |
Dshot parent object.
- Parameters
-
speed_hz | speed of the protocol |
bidirectional | set to true if the ESC is bidirectional. |
Definition at line 13 of file Dshot.cpp.
15 uint32_t max_ns = (1.f / (float) speed_hz) * 1000000000;
17 const static float T0H_percentage = 0.375;
18 const static float T1H_percentage = 0.75;
19 const static float T0L_percentage = 1 - T0H_percentage;
20 const static float T1L_percentage = 1 - T1H_percentage;
22 T0H_ns = max_ns * T0H_percentage;
23 T1H_ns = max_ns * T1H_percentage;
24 T0L_ns = max_ns * T0L_percentage;
25 T1L_ns = max_ns * T1L_percentage;
27 pthread_mutexattr_t swm_att;
28 pthread_mutexattr_init(&swm_att);
30 pthread_mutexattr_destroy(&swm_att);
pthread_mutex_t write_mut
◆ ~Dshot()
Definition at line 116 of file Dshot.cpp.
pthread_mutex_t write_mut
◆ _set()
Implementation of axis movement, this function is called from set(...)
.
Only gets called when axisMask match axis of Actuator.
- Parameters
-
axisMask | axis (can be multiple) to set speed to. |
speed | desired speed. |
- Returns
- err_t::OK if successful, others when not...
Implements aruna::movement::Actuator.
Definition at line 35 of file Dshot.cpp.
err_t set_speed(int16_t speed)
Set speed, use negative values to rotate in the other direction if bidirectional is enabled...
◆ _write_frame_continuous()
virtual err_t aruna::driver::Dshot::_write_frame_continuous |
( |
uint16_t |
dshot_frame | ) |
|
|
privatepure virtual |
◆ add_CRC()
void Dshot::add_CRC |
( |
uint16_t & |
bits | ) |
|
|
private |
add CRC to end of bit stream.
- Parameters
-
Definition at line 62 of file Dshot.cpp.
64 uint16_t csum_data = bits >> 4;
65 for (uint8_t i = 0; i < 3; i++) {
◆ arm_ESC()
Call the function after the constructor to arm the ESC.
set_speed() will not work without arming the ESC.
Definition at line 83 of file Dshot.cpp.
86 uint16_t start_value = 48;
88 uint8_t amount_of_steps = 40;
91 for (
int i = 0; i < amount_of_steps; ++i) {
96 for (
int i = amount_of_steps - 1; i > -1; --i) {
err_t write_frame_continuous(uint16_t dshot_frame)
Write set Dshot frame continuously on the bus.
err_t set_speed(int16_t speed)
Set speed, use negative values to rotate in the other direction if bidirectional is enabled...
uint16_t create_dshotFrame(uint16_t speed, uint8_t telemetry)
craft dshot package
◆ create_dshotFrame()
uint16_t Dshot::create_dshotFrame |
( |
uint16_t |
speed, |
|
|
uint8_t |
telemetry |
|
) |
| |
|
private |
craft dshot package
- Parameters
-
speed | keep between 48-2047 |
telemetry | 0 or 1 |
- Returns
- dshot bit package with CRC
Definition at line 75 of file Dshot.cpp.
76 uint16_t bit_frame = 0;
77 bit_frame =
speed << 5;
78 bit_frame |= telemetry << 4;
void add_CRC(uint16_t &bits)
add CRC to end of bit stream.
◆ get_bidirectional()
bool Dshot::get_bidirectional |
( |
| ) |
|
Is this Dshot driver birectional (can spin both ways)
- Returns
- true if is birectional, false if not.
Definition at line 124 of file Dshot.cpp.
◆ get_frequency()
uint32_t Dshot::get_frequency |
( |
| ) |
|
get frequency of the driver
- Returns
- frequency in hertz.
Definition at line 120 of file Dshot.cpp.
◆ set_bidirectional()
void Dshot::set_bidirectional |
( |
bool |
is_bidirectional | ) |
|
Set bidirectional property of the driver.
- Parameters
-
is_bidirectional | true is bidirectional, false if single directional. |
Definition at line 128 of file Dshot.cpp.
◆ set_speed()
err_t Dshot::set_speed |
( |
int16_t |
speed | ) |
|
Set speed, use negative values to rotate in the other direction if bidirectional is enabled.
- Parameters
-
- Returns
-
Definition at line 39 of file Dshot.cpp.
40 const static uint16_t MAX_VALUE = 2047;
41 const static uint16_t MIN_VALUE = 48;
42 const static uint16_t MID_VALUE = (MAX_VALUE + MIN_VALUE) / 2;
43 const static uint8_t telemetry = 0;
45 uint16_t max, min = 0;
47 max =
speed < 0 ? MID_VALUE : MAX_VALUE;
48 min =
speed < 0 ? MIN_VALUE : MID_VALUE;
static double convert_range(uint16_t input, float range_max=100.f, float range_min=0.f)
Convert uint16 to a new range.
err_t write_frame_continuous(uint16_t dshot_frame)
Write set Dshot frame continuously on the bus.
uint16_t create_dshotFrame(uint16_t speed, uint8_t telemetry)
craft dshot package
◆ write_frame_continuous()
err_t Dshot::write_frame_continuous |
( |
uint16_t |
dshot_frame | ) |
|
|
private |
Write set Dshot frame continuously on the bus.
- Parameters
-
dshot_frame | dhsot frame to send, already encoded in bits |
- Returns
-
Definition at line 108 of file Dshot.cpp.
virtual err_t _write_frame_continuous(uint16_t dshot_frame)=0
Write set Dshot frame continuously on the bus.
pthread_mutex_t write_mut
◆ _continues_write
bool aruna::driver::Dshot::_continues_write = false |
|
private |
◆ bidirectional
bool aruna::driver::Dshot::bidirectional |
|
private |
◆ frequency
const uint32_t aruna::driver::Dshot::frequency |
|
private |
◆ T0H_ns
uint16_t aruna::driver::Dshot::T0H_ns |
|
protected |
◆ T0L_ns
uint16_t aruna::driver::Dshot::T0L_ns |
|
protected |
◆ T1H_ns
uint16_t aruna::driver::Dshot::T1H_ns |
|
protected |
◆ T1L_ns
uint16_t aruna::driver::Dshot::T1L_ns |
|
protected |
◆ write_mut
pthread_mutex_t aruna::driver::Dshot::write_mut |
|
private |
The documentation for this class was generated from the following files: