Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,21 @@ def decode(self):
dshot_value = DshotCmd(self.dshot_cfg)
telem_value = DshotTelem(self.dshot_cfg)

last_dshot_value = DshotCmd(self.dshot_cfg)
last_telem_value = DshotTelem(self.dshot_cfg)

max_time_before_telem = 40e-6
max_samples_before_telem = int(max_time_before_telem / (1 / self.samplerate))

#bitseq = BitDshot()
while True:

match self.state:
case State.CMD:
match self.state_dshot:
case State_Dshot.RESET:
if dshot_value.crc_ok:
last_dshot_value = dshot_value
dshot_value = DshotCmd(self.dshot_cfg)
self.state_dshot = State_Dshot.START

Expand All @@ -175,6 +183,7 @@ def decode(self):
pins = self.wait([{0: 'r'}, {0: 'f'}, {'skip': self.dshot_cfg.samples_after_motorcmd}])
else:
pins = self.wait([{0: 'f'}, {0: 'r'}, {'skip': self.dshot_cfg.samples_after_motorcmd}])

#TODO: Increase skip to maximum time for effiency
#TODO: Mark any changes in this time as errors? Option to reduce load?

Expand All @@ -195,6 +204,11 @@ def decode(self):
if result:
self.display_dshot(dshot_value)
self.state_dshot = State_Dshot.RESET
#TODO: Change??
dshot_value.packet.es = self.samplenum
else:
#error, reset
self.state_dshot = State_Dshot.RESET
if result and self.dshot_cfg.bidirectional:
self.state = State.TELEM

Expand All @@ -221,10 +235,15 @@ def decode(self):
self.state_telem = State_Dshot.START

case State_Dshot.START:
if last_dshot_value.packet.es is not None:
if self.samplenum >= last_dshot_value.packet.es + max_samples_before_telem:
self.state_telem = State_Dshot.RESET
self.state = State.CMD
continue
# First wait for falling edge (idle high)
pins = self.wait([{0: 'f'}])
# Save start pulse
tlm_start = self.samplenum
telem_value.packet.ss = self.samplenum
# Switch to receiving state
self.state_telem = State_Dshot.RECV
# TODO: Check if still low after 1/8 bitlength for error det?
Expand Down
2 changes: 2 additions & 0 deletions protoDshot/protocols_motor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import reduce
from enum import Enum
from .dshot_bits import Sequence

gcr_tables = {
"0b11001": 0x0,
Expand Down Expand Up @@ -53,6 +54,7 @@ def __init__(self,settings_Dshot=DshotSettings()):
self.crc_ok = False
self.bits = 0
self.results = []
self.packet = Sequence()

def checkCRC(self,data,crc_recv):
self.crc_recv = crc_recv
Expand Down