Skip to content

Commit

Permalink
Merge branch 'main' into i2cFIxes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArendJan authored Aug 2, 2023
2 parents b6b9ea8 + 54f9cf9 commit 8abd8fe
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 40 deletions.
36 changes: 18 additions & 18 deletions mirte_telemetrix/config/mirte_user_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ distance:
pins:
trigger: GP9
echo: GP8
encoder:
left:
name: left
device: mirte
pins:
pin: GP15
right:
name: right
device: mirte
pins:
pin: GP14
#encoder:
# left:
# name: left
# device: mirte
# pins:
# pin: GP15
# right:
# name: right
# device: mirte
# pins:
# pin: GP14
intensity:
left:
name: left
Expand All @@ -40,13 +40,13 @@ intensity:
pins:
analog: GP27
digital: GP17
oled:
left:
name: left
device: mirte
pins:
sda: GP4
scl: GP5
#oled:
# left:
# name: left
# device: mirte
# pins:
# sda: GP4
# scl: GP5
# right:
# name: right
# device: mirte
Expand Down
21 changes: 11 additions & 10 deletions mirte_telemetrix/scripts/ROS_telemetrix_aio_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def analog_write(board, pin, value):
if board_mapping.get_mcu() == "pico":
await board.pwm_write(pin, value)
else:
await board.analog_write(board, pin, value)
await board.analog_write(pin, value)


# Import ROS message types
Expand Down Expand Up @@ -187,22 +187,25 @@ def get_data(self, req):
async def start(self):
await self.board.set_pin_mode_analog_input(
self.pins["pin"] - board_mapping.get_analog_offset(),
self.differential,
self.publish_data,
differential=self.differential,
callback=self.publish_data,
)

async def publish_data(self, data):
# Determine the key that is pressed
# TODO: these values were found on a 12 bits adc, and
# added a scaling for the actual bits used. We could
# calculate this with the R values used.
key = ""
if data[2] < 70:
if data[2] < 70 / 4096 * (2 ** board_mapping.get_adc_bits()):
key = "left"
elif data[2] < 230:
elif data[2] < 230 / 4096 * (2 ** board_mapping.get_adc_bits()):
key = "up"
elif data[2] < 410:
elif data[2] < 410 / 4096 * (2 ** board_mapping.get_adc_bits()):
key = "down"
elif data[2] < 620:
elif data[2] < 620 / 4096 * (2 ** board_mapping.get_adc_bits()):
key = "right"
elif data[2] < 880:
elif data[2] < 880 / 4096 * (2 ** board_mapping.get_adc_bits()):
key = "enter"

# Do some debouncing
Expand Down Expand Up @@ -770,7 +773,6 @@ async def handle_set_led_value(req):
# this one more often than another pin.
async def data_callback(data):
global pin_values
print("data callback")
pin_number = data[1]
if data[0] == 3:
pin_number += board_mapping.get_analog_offset()
Expand All @@ -797,7 +799,6 @@ def handle_get_pin_value(req):
asyncio.run(board.set_pin_mode_digital_input(pin, callback=data_callback))

while not pin in pin_values:
# print("sleeping pinvalues")
time.sleep(0.00001)

value = pin_values[pin]
Expand Down
4 changes: 4 additions & 0 deletions mirte_telemetrix/scripts/mappings/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ def get_analog_offset():
return 0


def get_adc_bits():
return 12


def get_max_pwm_value():
return 255
4 changes: 4 additions & 0 deletions mirte_telemetrix/scripts/mappings/nanoatmega328.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def get_analog_offset():
return 14


def get_adc_bits():
return 12


def get_max_pwm_value():
return 255

Expand Down
70 changes: 58 additions & 12 deletions mirte_telemetrix/scripts/mappings/pcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def get_analog_offset():
return board_mapping.get_analog_offset()


def get_adc_bits():
return board_mapping.get_adc_bits()


def connector_to_pins(connector):
if connector in connector_mapping:
return connector_mapping[connector]
Expand All @@ -67,12 +71,15 @@ def set_version(new_version, mcu=""):
if mcu == "" or mcu == "stm32":
board_mapping = mappings.stm32
connector_mapping = mirte_pcb04_stm_map
# else:
# board_mapping = mappings.nano
# connector_mapping = mirte_pcb04_nano_map
else:
board_mapping = mappings.nano
connector_mapping = mirte_pcb04_nano_map
if version == 0.3:
board_mapping = mappings.stm32
connector_mapping = mirte_pcb03_stm_map
if version == 0.2:
board_mapping = mappings.stm32
connector_mapping = mirte_pcb04_stm_map
connector_mapping = mirte_pcb02_stm_map


def get_max_pwm_value():
Expand All @@ -83,23 +90,62 @@ def get_max_pwm_value():

mirte_pcb04_stm_map = {
"IR1": {"digital": "C15", "analog": "A0"},
"IR2": {"digital": "B0", "analog": "A1"},
"IR2": {"digital": "A2", "analog": "A1"},
"SRF1": {"trigger": "A15", "echo": "C14"},
"SRF2": {"trigger": "A5", "echo": "A6"},
"I2C1": {"scl": "B6", "sda": "B7"},
"I2C2": {"scl": "B10", "sda": "B11"},
"ENCA": {"pin": "B4"},
"ENCB": {"pin": "B12"},
"ENCA": {"pin": "B12"},
"ENCB": {"pin": "B4"},
"MISC1": {"pin": "B0"},
"MISC2": {"pin": "B1"},
"Keypad": {"pin": "A4"},
"Servo1": {"pin": "B5"},
"Servo2": {"pin": "A7"},
"Servo1": {"pin": "B3"},
"Servo2": {"pin": "A3"},
"LED": {"pin": "C13"},
"MA": {"1a": "A8", "1b": "B3"},
"MA": {"1a": "A8", "1b": "B5"},
"MB": {"1a": "B14", "1b": "B15"},
"MC": {"1a": "B1", "1b": "A10"},
"MD": {"1a": "A9", "1b": "B13"},
"MC": {"1a": "A10", "1b": "A7"},
"MD": {"1a": "B13", "1b": "A9"},
}

mirte_pcb04_nano_map = {
"IR1": {"digital": "A7", "analog": "A1"},
"IR2": {"digital": "A6", "analog": "A0"},
"SRF1": {"trigger": "D9", "echo": "D8"},
"SRF2": {"trigger": "D11", "echo": "D10"},
"I2C1": {"scl": "A5", "sda": "A4"},
"ENCA": {"pin": "D2"},
"ENCB": {"pin": "D3"},
"Servo1": {"pin": "A3"},
"Servo2": {"pin": "D12"},
"LED": {"pin": "D13"},
"MA": {"1a": "D6", "1b": "D7"},
"MB": {"1a": "D4", "1b": "D5"},
}

mirte_pcb03_stm_map = {
"IR1": {"digital": "C15", "analog": "A0"},
"IR2": {"digital": "B0", "analog": "A1"},
"SRF1": {"trigger": "A5", "echo": "A6"},
"SRF2": {"trigger": "B7", "echo": "C14"},
"I2C1": {"scl": "B6", "sda": "B7"},
"I2C2": {"scl": "B10", "sda": "B11"},
"ENCA": {"pin": "B12"},
"ENCB": {"pin": "B4"},
"Keypad": {"pin": "A4"},
"Servo1": {"pin": "B5"},
"Servo1": {"pin": "A7"},
"A2": {"pin": "A2"},
"A3": {"pin": "A3"},
"LED": {"pin": "C13"},
"MC1A": {"1a": "A8", "1b": "B3"},
"MC1B": {"1a": "B14", "1b": "B15"},
"MC2A": {"1a": "A10", "1b": "B1"},
"MC2B": {"1a": "B13", "1b": "A9"},
}


mirte_pcb02_stm_map = {
"IR1": {"digital": "B1", "analog": "A0"},
"IR2": {"digital": "B0", "analog": "A1"},
Expand Down
6 changes: 6 additions & 0 deletions mirte_telemetrix/scripts/mappings/pico.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def get_analog_offset():
return 26


def get_adc_bits():
# NOTE: the pico itself has 12 bits, but micropython will upgrade to 16
# no clue why 14 works
return 14


def get_max_pwm_value():
return 100

Expand Down
4 changes: 4 additions & 0 deletions mirte_telemetrix/scripts/mappings/stm32.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def get_analog_offset():
return 20


def get_adc_bits():
return 12


def pin_name_to_pin_number(pin):
if pin in stm32_map:
return stm32_map[pin]
Expand Down

0 comments on commit 8abd8fe

Please sign in to comment.