Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the roboclawtest.py script more user friendly #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
45 changes: 24 additions & 21 deletions scripts/roboclawtest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# A short and sweet script to test communication with a single roboclaw motor controller.
# usage
# $ python roboclawtest.py 128
# Things are working if you don't get an error and you see something like:
# (1, 'USB Roboclaw 2x7a v4.1.34\n')
# (1, 4314, 128)

from time import sleep
import sys
Expand All @@ -12,29 +9,35 @@
sys.path.append(path.join(path.expanduser('~'), 'osr_ws/src/osr-rover-code/ROS/osr_control/osr_control'))
from roboclaw import Roboclaw


if __name__ == "__main__":

address = int(sys.argv[1])
roboclaw0 = Roboclaw("/dev/serial0", 115200)
roboclaw1 = Roboclaw("/dev/serial1", 115200)
connected0 = roboclaw0.Open() == 1
connected1 = roboclaw1.Open() == 1
one_connected = False
if connected0:
print("Connected to /dev/serial0.")
print(f"Address: {address}")
print("ReadVersion:", roboclaw0.ReadVersion(address))
print("ReadEncM1:", roboclaw0.ReadEncM1(address))
battery = roboclaw0.ReadMainBatteryVoltage(address)
print(f"Address {address} - ReadMainBatteryVoltage: {battery}")
one_connected = True
if connected1:
print("Connected to /dev/serial1.")
print(f"Address: {address}")
print("ReadVersion:", roboclaw1.ReadVersion(address))
print("ReadEncM1:", roboclaw1.ReadEncM1(address))
battery = roboclaw1.ReadMainBatteryVoltage(address)
print(f"Address {address} - ReadMainBatteryVoltage: {battery}")
one_connected = True
if not one_connected:

for rc in [roboclaw0, roboclaw1]:
connected = rc.Open() == 1
if not connected:
continue
print(f"Found open comport {rc._port}, attempting to communicate with address {address}")
version = rc.ReadVersion(address)
if version[0] == 1:
print(f"Successfully connected, roboclaw firmware version: {version[1]}")
else:
print("Failed to read version, did not get response from roboclaw. Make sure it is properly connected.")
continue
enc1 = rc.ReadEncM1(address)
enc2 = rc.ReadEncM2(address)
battery = rc.ReadMainBatteryVoltage(address)
if enc1[0] == 1 and enc2[0] == 1 and battery[0] == 1:
print(f"Encoder for M1 = {enc1[1]}, M2 = {enc2[1]}. Roboclaw input voltage: {battery[1]}")
break # don't need to try the other port
else:
print("Failed to read encoder and/or battery values, connection is unstable. Check your wiring.")
print(f"Raw responses: Encoder M1: {enc1}, Encoder M2: {enc2}, Battery: {battery}. A (0, value) response means no response.")

if not connected:
print("Could not open comport /dev/serial0 or /dev/serial1, make sure it has the correct permissions and is available")