saving Arni 0.1.0 firmware

master
Drew Bednar 3 years ago
parent df911dcfb0
commit 1ad857a8b5

@ -8,7 +8,7 @@ driven by an Odrive.
```
upy put bluetooth/esp32/arni/ble_advertising.py ble_advertising.py
upy put bluetooth/esp32/arni/robot.py robot.py
upy put bluetooth/esp32/ble_arni_odrive_controller.py main.py
upy put bluetooth/esp32/arni/ble_arni_odrive_controller.py main.py
```
Confirm with `upy ls`
@ -16,7 +16,7 @@ Confirm with `upy ls`
## Usage
With the ESP32 and Odrive powered on open the Dabble and connect. This
does not support Joystick yet. This is a work in progress
does not support Joystick yet. This is a work in progress.
### Buttons

@ -99,12 +99,9 @@ class BLEUART:
def _advertise(self, interval_us=500000):
self._ble.gap_advertise(interval_us, adv_data=self._payload)
def main():
import time
# Pin 17 white wire to odrive gpio2. Grey pin 16 wire to odrive gpio1
robot_uart = UART(2, baudrate=115200, tx=17, rx=16)
arni = ArniRobot(robot_uart)
robot_controller = RobotController(arni)
@ -121,7 +118,7 @@ def main():
# for count, v in enumerate(data):
# print("Index: {0} | Value: {1} | Binary: {2} | Hex: {3}".format(count,v,bin(v), hex(v)))
if len(data) == 8:
print("Recieved {} data".format(data))
print("Received {} data".format(data))
robot_controller.interpret((data[5],data[6]))
# Will execute this function on every received packet

@ -50,7 +50,7 @@ class RobotController:
:return:
"""
self._interpret_buttons(dabble_bytes[0])
self._interpret_arrows(dabble_bytes[1])
self._interpret_arrows(dabble_bytes[0], dabble_bytes[1])
def _interpret_buttons(self, button_byte):
if button_byte & (1 << DABBLE_START_BIT):
@ -60,9 +60,21 @@ class RobotController:
self.robot.set_idle()
else:
self.robot.set_active()
def _interpret_arrows(self, arrow_byte):
if arrow_byte & (1 << DABBLE_UP_BIT):
# Speed control
if button_byte & (1 << DABBLE_TRIANGLE_BIT):
self.robot._vel += 0.2
elif button_byte & (1 << DABBLE_CROSS_BIT):
self.robot._vel -= 0.2
def _interpret_arrows(self, button_byte, arrow_byte):
# Spin overrides arrow pad
if button_byte & (1 << DABBLE_CIRCLE_BIT):
self.robot.right_spin()
elif button_byte & (1 << DABBLE_SQUARE_BIT):
self.robot.left_spin()
# Arrow Pad assessment
elif arrow_byte & (1 << DABBLE_UP_BIT):
self.robot.forward()
elif arrow_byte & (1 << DABBLE_DOWN_BIT):
self.robot.reverse()
@ -119,11 +131,19 @@ class ArniRobot:
def right(self):
"""Hard turn right."""
return self._uart.write('v 0 0 0\nv 1 -{0} 0\n'.format(self._vel))
return self._uart.write('v 0 {0} 0\nv 1 -{1} 0\n'.format(self._vel/8,self._vel))
def right_spin(self):
"""Spins clockwise in place."""
return self._uart.write('v 0 -{0} 0\nv 1 -{0} 0\n'.format(self._vel, self._vel))
def left(self):
"""Hard turn left."""
return self._uart.write('v 0 {0} 0\nv 1 0 0\n'.format(self._vel))
return self._uart.write('v 0 {0} 0\nv 1 -{1} 0\n'.format(self._vel,self._vel/8))
def left_spin(self):
"""Spins counter-clockwise in place."""
return self._uart.write('v 0 {0} 0\nv 1 {0} 0\n'.format(self._vel, self._vel))
def right_forward(self):
"""Right turn while moving forward."""

Loading…
Cancel
Save