Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Multidrive remote + touch interface fix #80

Open
wants to merge 16 commits into
base: multidrive-remote
Choose a base branch
from
Open
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
File renamed without changes.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
git+https://github.com/2bndy5/Adafruit_CircuitPython_LSM9DS1.git
git+https://github.com/2bndy5/CircuitPython_MPU6050.git
adafruit_circuitpython_lsm9ds1==2.0.5
adafruit_circuitpython_mpu6050==1.0.1
git+https://github.com/DVC-Viking-Robotics/Drivetrain.git
git+https://github.com/DVC-Viking-Robotics/GPS_Serial.git
circuitpython-nrf24l01==1.1.0
Expand Down
51 changes: 45 additions & 6 deletions webapp/inputs/HWconfig_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,56 @@
}
],
"type":"Tank",
"max speed":"85"
"max speed":"85",
"name":"integrated drive"
},
{
"motors":[
{
"driver":"NRF24L01",
"address":"5,8",
"name":"rfpi0"
"driver":"NRF24L01tx",
"address":"5,4",
"name":"rfpi0",
"cmd_template":"llb"
}
],
"type":"External"
"type":"nRF24L01",
"name":"RF 2.4GHz"
},
{
"motors":[
{
"driver":"ROBOCLAW",
"address":"/dev/ttyUSB0"
}
],
"type":"Roboclaw",
"name":"MIEL"
},
{
"motors":[
{
"driver":"Solenoid",
"address":"22,13"
}
],
"switch_pin":"4",
"type":"Locomotive",
"name":"Railroad drive"
},
{
"motors":[
{
"driver":"BiMotor",
"address":"22,13"
},
{
"driver":"BiMotor",
"address":"17,18"
}
],
"type":"Automotive",
"max speed":"85",
"name":"RC Car drive"
}
],
"IMU":[
Expand Down Expand Up @@ -53,4 +92,4 @@
"address":"/dev/ttyACM0"
}
]
}
}
33 changes: 18 additions & 15 deletions webapp/inputs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
pass # addressed by has_gpio_pins variable
from gps_serial import GPSserial
from .check_platform import ON_RASPI, ON_JETSON
from .ext_node import ROBOCLAW

if ON_RASPI:
from drivetrain.drivetrain import Tank, Automotive, External
from drivetrain.motor import Solenoid, BiMotor, PhasedMotor, NRF24L01, USB
from drivetrain import Tank, Automotive, Locomotive, Solenoid, BiMotor, PhasedMotor, NRF24L01tx
from adafruit_lsm9ds1 import LSM9DS1_I2C
from circuitpython_mpu6050 import MPU6050
from adafruit_mpu6050 import MPU6050
from circuitpython_nrf24l01 import RF24
from digitalio import DigitalInOut as Dio

from .imu import MAG3110

Expand Down Expand Up @@ -58,7 +60,7 @@
'27': board.D27,
}

d_train = []
d_train = {}
IMUs = []
gps = []
nav = None
Expand All @@ -67,7 +69,7 @@
if 'Drivetrains' in SYSTEM_CONF['Check-Hardware']:
# handle drivetrain
for d in SYSTEM_CONF['Drivetrains']:
if d['type'] in ('Tank', 'Automotive', 'External'):
if d['type'] in ('Tank', 'Automotive', 'Locomotive', 'nRF24L01', 'Roboclaw'):
# instantiate motors
motors = []
for m in d['motors']:
Expand All @@ -83,18 +85,19 @@
motors.append(BiMotor(pins))
elif m['driver'].startswith('PhasedMotor') and len(pins) == 2 and has_gpio_pins:
motors.append(PhasedMotor(pins))
elif m['driver'].startswith('NRF24L01') and has_gpio_pins:
motors.append(
NRF24L01(SPI_BUS, pins, bytes(m['name'].encode('utf-8'))))
elif m['driver'].startswith('USB'):
motors.append(USB(m['address']))
elif m['driver'].startswith('ROBOCLAW'):
d_train[d["name"]] = ROBOCLAW(m['address'])
elif m['driver'].startswith('NRF24L01tx') and has_gpio_pins:
d_train[d["name"]] = NRF24L01tx(
RF24(SPI_BUS, Dio(pins[0]), Dio(pins[1])),
address=bytes(m['name'].encode()),
cmd_template=m['cmd_template'])
if d['type'].startswith('Tank') and has_gpio_pins:
d_train.append(Tank(motors, int(d['max speed'])))
d_train[d["name"]] = Tank(motors, int(d['max speed']))
elif d['type'].startswith('Automotive') and has_gpio_pins:
d_train.append(Automotive(motors, int(d['max speed'])))
elif d['type'].startswith('External'):
if motors:
d_train.append(External(motors[0]))
d_train[d["name"]] = Automotive(motors, int(d['max speed']))
elif d['type'].startswith('Locomotive') and has_gpio_pins:
d_train[d["name"]] = Locomotive(motors, RPI_PIN_ALIAS[d['switch_pin']])

if 'IMU' in SYSTEM_CONF['Check-Hardware']:
for imu in SYSTEM_CONF['IMU']:
Expand Down
31 changes: 31 additions & 0 deletions webapp/inputs/ext_node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
A collection of wrapper classes that extend communication with external devices (ie arduino or another raspberry pi)
"""
from webapp.outputs.roboclaw_3 import Roboclaw

class EXTnode():
"""
Expand Down Expand Up @@ -29,3 +30,33 @@ def get_all_data(self):
if temp:
self.heading = float(temp[0])
return self.heading

class ROBOCLAW:
def __init__(self, address, claw_address=0x80):
self._address = claw_address
self._device = Roboclaw(address, 38400)
self._device.Open()

def go(self, cmds):
if len(cmds) < 2:
raise ValueError('Commands list needs to be atleast 2 items long')
cmds[0] = max(-65535, min(65535, cmds[0]))
cmds[1] = max(-65535, min(65535, cmds[1]))
left = cmds[1]
right = cmds[1]
if not cmds[1]:
# if forward/backward axis is null ("turning on a dime" functionality)
# re-apply speed governor to only axis with a non-zero value
right = cmds[0]
left = cmds[0] * -1
else:
# if forward/backward axis is not null and left/right axis is not null
# apply differential to motors accordingly
offset = (65535 - abs(cmds[0])) / 65535.0
if cmds[0] > 0:
right *= offset
elif cmds[0] < 0:
left *= offset
# send translated commands to motors
self._device.ForwardBackwardM1(self._address, int(left * 127 / 131070 + 64))
self._device.ForwardBackwardM2(self._address, int(right * 127 / 131070 + 64))
Loading