13 Dshot::Dshot(uint32_t speed_hz,
bool bidirectional): frequency(speed_hz), bidirectional(bidirectional) {
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);
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;
53 uint16_t adjusted_speed = (uint16_t)
convert_range(abs(speed), max, min);
64 uint16_t csum_data = bits >> 4;
65 for (uint8_t i = 0; i < 3; i++) {
76 uint16_t bit_frame = 0;
77 bit_frame = speed << 5;
78 bit_frame |= telemetry << 4;
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) {
uint32_t get_frequency()
get frequency of the driver
err_t _set(movement::axis_mask_t axisMask, int16_t speed) override
Implementation of axis movement, this function is called from set(...).
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.
void add_CRC(uint16_t &bits)
add CRC to end of bit stream.
Dshot(uint32_t speed_hz=150000, bool bidirectional=false)
Dshot parent object.
bool get_bidirectional()
Is this Dshot driver birectional (can spin both ways)
void set_bidirectional(bool is_bidirectional)
Set bidirectional property of the driver.
err_t set_speed(int16_t speed)
Set speed, use negative values to rotate in the other direction if bidirectional is enabled...
virtual err_t _write_frame_continuous(uint16_t dshot_frame)=0
Write set Dshot frame continuously on the bus.
void arm_ESC()
Call the function after the constructor to arm the ESC.
pthread_mutex_t write_mut
uint16_t create_dshotFrame(uint16_t speed, uint8_t telemetry)
craft dshot package