Vanilla (examples from original library)

Bare Minimum

examples/roboclaw_bareminimum.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
"""bare minimum example shows you """
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:  # try MicroPythom
        from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
rc = Roboclaw(UART("COM10", 38400))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 38400))
# if CircuitPython or MicroPythom
# rc = Roboclaw(UART(rate=38400))

Simple PWM

examples/roboclaw_simplepwm.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)

while 1:
    rc.forward_m1(32)  # 1/4 power forward
    rc.backward_m2(32)  # 1/4 power backward
    time.sleep(2)

    rc.backward_m1(32)  # 1/4 power backward
    rc.forward_m2(32)  # 1/4 power forward
    time.sleep(2)

    rc.backward_m1(0)  # Stopped
    rc.forward_m2(0)  # Stopped
    time.sleep(2)

    m1duty = 16
    m2duty = -16
    rc.forward_backward_m1(64+m1duty)  # 1/4 power forward
    rc.forward_backward_m2(64+m2duty)  # 1/4 power backward
    time.sleep(2)

    m1duty = -16
    m2duty = 16
    rc.forward_backward_m1(64+m1duty)  # 1/4 power backward
    rc.forward_backward_m2(64+m2duty)  # 1/4 power forward
    time.sleep(2)

    rc.forward_backward_m1(64)  # Stopped
    rc.forward_backward_m2(64)  # Stopped
    time.sleep(2)

Mixed PWM

examples/roboclaw_mixedpwm.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)

rc.forward_mixed(0)
rc.turn_right_mixed(0)


def test(loop=2):
    while loop:
        rc.forward_mixed(32)
        time.sleep(2)
        rc.backward_mixed(32)
        time.sleep(2)
        rc.turn_right_mixed(32)
        time.sleep(2)
        rc.turn_left_mixed(32)
        time.sleep(2)
        rc.forward_mixed(0)
        rc.turn_right_mixed(32)
        time.sleep(2)
        rc.turn_left_mixed(32)
        time.sleep(2)
        rc.turn_right_mixed(0)
        time.sleep(2)
        loop -= 1

Speed

examples/roboclaw_speed.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# ***Before using this example the motor/controller combination must be
# ***tuned and the settings saved to the Roboclaw using IonMotion.
# ***The Min and Max Positions must be at least 0 and 50000

import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)


def displayspeed():
	enc1 = rc.read_encoder_m1()
	enc2 = rc.read_encoder_m2()
	speed1 = rc.read_speed_m1()
	speed2 = rc.read_speed_m2()

	print("Encoder1:"),
	if(enc1[0] == 1):
		print enc1[1],
		print format(enc1[2], '02x'),
	else:
		print "failed",
	print "Encoder2:",
	if(enc2[0] == 1):
		print enc2[1],
		print format(enc2[2], '02x'),
	else:
		print "failed ",
	print "Speed1:",
	if(speed1[0]):
		print speed1[1],
	else:
		print "failed",
	print("Speed2:"),
	if(speed2[0]):
		print speed2[1]
	else:
		print "failed "


version = rc.read_version(
if version[0] == False:
	print "GETVERSION Failed"
else:
	print repr(version[1])

while 1:
	rc.speed_m1(12000)
	rc.speed_m2(-12000)
	for i in range(0, 200):
		displayspeed()
		time.sleep(0.01)

	rc.speed_m1(-12000)
	rc.speed_m2(12000)
	for i in range(0, 200):
		displayspeed()
		time.sleep(0.01)

Speed and Acceleration

examples/roboclaw_speedaccel.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# ***Before using this example the motor/controller combination must be
# ***tuned and the settings saved to the Roboclaw using IonMotion.
# ***The Min and Max Positions must be at least 0 and 50000

import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)


def displayspeed():
    enc1 = rc.read_encoder_m1()
    enc2 = rc.read_encoder_m2()
    speed1 = rc.read_speed_m1()
    speed2 = rc.read_speed_m2()
    print("Encoder1:")
    if enc1[0] == 1:
        print(enc1[1])
        print(format(enc1[2], '02x'))
    else:
        print("failed")
    print("Encoder2:")
    if enc2[0] == 1:
        print(enc2[1])
        print(format(enc2[2], '02x'))
    else:
        print("failed ")
    print("Speed1:")
    if speed1[0]:
        print(speed1[1])
    else:
        print("failed")
    print("Speed2:")
    if speed2[0]:
        print(speed2[1])
    else:
        print("failed ")


version = rc.ReadVersion()
if version[0] == False:
    print("GETVERSION Failed")
else:
    print(repr(version[1]))

while 1:
    rc.speed_accel_m1(12000, 12000)
    rc.speed_accel_m2(12000, -12000)
    for i in range(0, 200):
        displayspeed()
        time.sleep(0.01)

    rc.speed_accel_m1(12000, -12000)
    rc.speed_accel_m2(12000, 12000)
    for i in range(0, 200):
        displayspeed()
        time.sleep(0.01)

Speed, Acceleration, and Distance

examples/roboclaw_speedacceldistance.py
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
# ***Before using this example the motor/controller combination must be
# ***tuned and the settings saved to the Roboclaw using IonMotion.
# ***The Min and Max Positions must be at least 0 and 50000

import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)


def displayspeed():
    enc1 = rc.read_encoder_m1()
    enc2 = rc.read_encoder_m2()
    speed1 = rc.read_speed_m1()
    speed2 = rc.read_speed_m2()

    print("Encoder1:")
    if enc1[0] == 1:
        print(enc1[1])
        print(format(enc1[2], '02x'))
    else:
        print("failed")
    print("Encoder2:")
    if enc2[0] == 1:
        print(enc2[1])
        print(format(enc2[2], '02x'))
    else:
        print("failed ")
    print("Speed1:")
    if speed1[0]:
        print(speed1[1])
    else:
        print("failed")
    print("Speed2:")
    if speed2[0]:
        print(speed2[1])
    else:
        print("failed ")


version = rc.read_version()
if version[0] == False:
    print("GETVERSION Failed")
else:
    print(repr(version[1]))

while 1:
    rc.speed_accel_distance_m1(12000, 12000, 42000, 1)
    rc.speed_accel_distance_m2(12000, -12000, 42000, 1)

    # distance travelled is v*v/2a = 12000*12000/2*48000 = 1500
    rc.speed_accel_distance_m1(12000, 0, 0, 0)

    # that makes the total move in one direction 48000
    rc.speed_accel_distance_m2(12000, 0, 0, 0)

    buffers = (0, 0, 0)

    # Loop until distance command has completed
    while(buffers[1] != 0x80 and buffers[2] != 0x80):
        print("Buffers: ")
        print(buffers[1])
        print(" ")
        print(buffers[2])
        displayspeed()
        buffers = rc.ReadBuffers()

    time.sleep(1)

    rc.speed_accel_distance_m1(48000, -12000, 46500, 1)
    rc.speed_accel_distance_m2(48000, 12000, 46500, 1)

    # distance travelled is v*v/2a = 12000*12000/2*48000 = 1500
    rc.speed_accel_distance_m1(48000, 0, 0, 0)
    # that makes the total move in one direction 48000
    rc.speed_accel_distance_m2(48000, 0, 0, 0)

    buffers = (0, 0, 0)
    # Loop until distance command has completed
    while(buffers[1] != 0x80 and buffers[2] != 0x80):
        print("Buffers: ")
        print(buffers[1])
        print(" ")
        print(buffers[2])
        displayspeed()
        buffers = rc.read_buffer_length()

    # When no second command is given the motors will automatically slow down to 0 which takes 1 second
    time.sleep(1)

Speed and Distance

examples/roboclaw_speeddistance.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# ***Before using this example the motor/controller combination must be
# ***tuned and the settings saved to the Roboclaw using IonMotion.
# ***The Min and Max Positions must be at least 0 and 50000

import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)


def displayspeed():
    enc1 = rc.read_encoder_m1()
    enc2 = rc.read_encoder_m2()
    speed1 = rc.read_speed_m1()
    speed2 = rc.read_speed_m2()

    print("Encoder1:")
    if enc1[0] == 1:
        print(enc1[1])
        print(format(enc1[2], '02x'))
    else:
        print("failed")
    print("Encoder2:")
    if enc2[0] == 1:
        print(enc2[1])
        print(format(enc2[2], '02x'))
    else:
        print("failed ")
    print("Speed1:")
    if speed1[0]:
        print(speed1[1])
    else:
        print("failed")
    print("Speed2:")
    if speed2[0]:
        print(speed2[1])
    else:
        print("failed ")


version = rc.read_version()
if version[0] == False:
    print("GETVERSION Failed")
else:
    print(repr(version[1]))

while 1:
    rc.speed_distance_m1(12000, 48000, 1)
    rc.speed_distance_m2(-12000, 48000, 1)
    buffers = (0, 0, 0)
    # Loop until distance command has completed
    while(buffers[1] != 0x80 and buffers[2] != 0x80):
        displayspeed()
        buffers = rc.read_buffer_length()

    time.sleep(2)

    rc.speed_distance_m1(-12000, 48000, 1)
    rc.speed_distance_m2(12000, 48000, 1)
    buffers = (0, 0, 0)
    # Loop until distance command has completed
    while(buffers[1] != 0x80 and buffers[2] != 0x80):
        displayspeed()
        buffers = rc.read_buffer_length()

    # When no second command is given the motors will automatically slow down to 0 which takes 1 second
    time.sleep(2)

    rc.speed_distance_m1(12000, 48000, 1)
    rc.speed_distance_m2(-12000, 48000, 1)
    rc.speed_distance_m1(-12000, 48000, 0)
    rc.speed_distance_m2(12000, 48000, 0)
    rc.speed_distance_m1(0, 48000, 0)
    rc.speed_distance_m2(0, 48000, 0)
    buffers = (0, 0, 0)
    # Loop until distance command has completed
    while(buffers[1] != 0x80 and buffers[2] != 0x80):
        displayspeed()
        buffers = rc.read_buffer_length()

    time.sleep(1)

Mixed Speed and Acceleration

examples/roboclaw_mixedspeedaccel.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# ***Before using this example the motor/controller combination must be
# ***tuned and the settings saved to the Roboclaw using IonMotion.
# ***The Min and Max Positions must be at least 0 and 50000

import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)


def displayspeed():
    enc1 = rc.read_encoder_m1()
    enc2 = rc.read_encoder_m2()
    speed1 = rc.read_speed_m1()
    speed2 = rc.read_speed_m2()

     print("Encoder1:")
       if enc1[0] == 1:
            print(enc1[1])
            print(format(enc1[2], '02x'))
        else:
            print("failed")
        print("Encoder2:")
        if enc2[0] == 1:
            print(enc2[1])
            print(format(enc2[2], '02x'))
        else:
            print("failed ")
        print("Speed1:")
        if speed1[0]:
            print(speed1[1])
        else:
            print("failed")
        print("Speed2:")
        if(speed2[0]):
            print(speed2[1])
        else:
            print("failed ")


version = rc.ReadVersion()
if version[0] == False:
    print("GETVERSION Failed")
else:
    print(repr(version[1]))

while 1:
    rc.speed_accel_m1_m2(12000, 12000, -12000)
    for i in range(0, 200):
        displayspeed()
        time.sleep(0.01)

    rc.speed_accel_m1_m2(12000, -12000, 12000)
    for i in range(0, 200):
        displayspeed()
        time.sleep(0.01)

Position

examples/roboclaw_position.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# ***Before using this example the motor/controller combination must be
# ***tuned and the settings saved to the Roboclaw using IonMotion.
# ***The Min and Max Positions must be at least 0 and 50000

import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)


def displayspeed():
    enc1 = rc.read_encoder_m1()
    enc2 = rc.read_encoder_m2()
    speed1 = rc.read_speed_m1()
    speed2 = rc.read_speed_m2()

    print("Encoder1:")
    if enc1[0] == 1:
        print(enc1[1])
        print(format(enc1[2], '02x'))
    else:
        print("failed")
    print("Encoder2:")
    if enc2[0] == 1:
        print(enc2[1])
        print(format(enc2[2], '02x'))
    else:
        print("failed ")
    print("Speed1:")
    if speed1[0]:
        print(speed1[1])
    else:
        print("failed")
    print("Speed2:")
    if speed2[0]:
        print(speed2[1])
    else:
        print("failed ")


while 1:
    print("Pos 50000")
    rc.speed_accel_deccel_position_m1(32000, 12000, 32000, 50000, 0)
    for i in range(0, 80):
        displayspeed()
        time.sleep(0.1)

    time.sleep(2)

    print("Pos 0")
    rc.speed_accel_deccel_position_m1(32000, 12000, 32000, 0, 0)
    for i in range(0, 80):
        displayspeed()
        time.sleep(0.1)

    time.sleep(2)

RC mode Pulses

examples/roboclaw_rcpulses.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
""" On Roboclaw set switch 1 and 6 on. """
import time
from board import SCL, SDA
import busio

# Import the PCA9685 module. Available in the bundle and here:
#   https://github.com/adafruit/Adafruit_CircuitPython_PCA9685
from adafruit_pca9685 import PCA9685

from adafruit_motor import servo

i2c = busio.I2C(SCL, SDA)

# Create a simple PCA9685 class instance.
pca = PCA9685(i2c)
# You can optionally provide a finer tuned reference clock speed to improve the accuracy of the
# timing pulses. This calibration will be specific to each board and its environment. See the
# calibration.py example in the PCA9685 driver.
# pca = PCA9685(i2c, reference_clock_speed=25630710)
pca.frequency = 50

# The pulse range is [1250 (full forward), 1750 (full reverse)].
pulses[
    servo.ContinuousServo(pca.channels[7], min_pulse=1250, max_pulse=1750),
    servo.ContinuousServo(pca.channels[8], min_pulse=1250, max_pulse=1750)
]

pulses[0].throttle = 1
pulses[1].throttle = -1
time.sleep(2)

# stop
pulses[0].throttle = 0
pulses[1].throttle = 0

pca.deinit()

RC mode Pulses Mixed

examples/roboclaw_rcpulsemixed.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# On Roboclaw set switch 1 and 6 on. <-- what does this refer to?
# mode 2 option 4 <-- my note based on user manual pg 26
import time
from board import SCL, SDA
import busio

# Import the PCA9685 module. Available in the bundle and here:
#   https://github.com/adafruit/Adafruit_CircuitPython_PCA9685
from adafruit_pca9685 import PCA9685

from adafruit_motor import servo

i2c = busio.I2C(SCL, SDA)

# Create a simple PCA9685 class instance.
pca = PCA9685(i2c)
# You can optionally provide a finer tuned reference clock speed to improve the accuracy of the
# timing pulses. This calibration will be specific to each board and its environment. See the
# calibration.py example in the PCA9685 driver.
# pca = PCA9685(i2c, reference_clock_speed=25630710)
pca.frequency = 50

# The pulse range is [1250 (full forward), 1750 (full reverse)].
pulses[
    servo.ContinuousServo(pca.channels[7], min_pulse=1250, max_pulse=1750),
    servo.ContinuousServo(pca.channels[8], min_pulse=1250, max_pulse=1750)
]

# TODO MATH OF PULSE INTO FLOAT RANGE [-1, 1]
while 1:
  //forward
  pulses[0].throttle = 1 # writeMicroseconds(1600);
  pulses[1].throttle = 1 # writeMicroseconds(1500);
  time.sleep(2)

  //backward
  pulses[0].throttle = 1 # writeMicroseconds(1400);
  pulses[1].throttle = 1 # writeMicroseconds(1500);
  time.sleep(2)

  //left
  pulses[0].throttle = 1 # writeMicroseconds(1500);
  pulses[1].throttle = 1 # writeMicroseconds(1600);
  time.sleep(2)

  //right
  pulses[0].throttle = 1 # writeMicroseconds(1500);
  pulses[1].throttle = 1 # writeMicroseconds(1400);
  time.sleep(2)

  //mixed forward/left
  pulses[0].throttle = 1 # writeMicroseconds(1600);
  pulses[1].throttle = 1 # writeMicroseconds(1600);
  time.sleep(2)

  //mixed forward/right
  pulses[0].throttle = 1 # writeMicroseconds(1600);
  pulses[1].throttle = 1 # writeMicroseconds(1400);
  time.sleep(2)

  //mixed backward/left
  pulses[0].throttle = 1 # writeMicroseconds(1400);
  pulses[1].throttle = 1 # writeMicroseconds(1600);
  time.sleep(2)

  //mixed backward/right
  pulses[0].throttle = 1 # writeMicroseconds(1400);
  pulses[1].throttle = 1 # writeMicroseconds(1400);
  time.sleep(2)

}

Read Various Data

examples/roboclaw_read.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)


def displayspeed():
    enc1 = rc.read_encoder_m1()
    enc2 = rc.read_encoder_m2()
    speed1 = rc.read_speed_m1()
    speed2 = rc.read_speed_m2()

     print("Encoder1:")
       if enc1[0] == 1:
            print(enc1[1])
            print(format(enc1[2], '02x'))
        else:
            print("failed")
        print("Encoder2:")
        if enc2[0] == 1:
            print(enc2[1])
            print(format(enc2[2], '02x'))
        else:
            print("failed ")
        print("Speed1:")
        if speed1[0]:
            print(speed1[1])
        else:
            print("failed")
        print("Speed2:")
        if speed2[0]:
            print(speed2[1])
        else:
            print("failed ")


version = rc.ReadVersion()
if version[0] == False:
    print("GETVERSION Failed")
else:
    print(repr(version[1]))


def test(loop=2):
    while loop:
        displayspeed()
        loop -= 1

Read Version

examples/roboclaw_readversion.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)

while 1:
        # Get version string
    version = rc.read_version()
    if version[0] == False:
        print("GETVERSION Failed")
    else:
        print(repr(version[1]))
    time.sleep(1)

Read EEPROM

examples/roboclaw_readeeprom.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import time
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)

# Get version string
for x in range(0, 255):
    value = rc.read_eeprom(x)
    print("EEPROM:")
    print(x)
    print(" ")
    if value[0] == False:
        print("Failed")
    else:
        print(value[1])

Write EEPROM

examples/roboclaw_writeeeprom.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from roboclaw import Roboclaw
try:  # if on win32 or linux
    from serial import SerialException, Serial as UART
except ImportError:
    try:  # try CircuitPython
        from board import UART
    except ImportError:
        try:  # try MicroPythom
            from roboclaw.usart_serial_ctx import SerialUART as UART

# Windows comport name
# rc = Roboclaw(UART("COM3", 115200))
# Linux comport name
# rc = Roboclaw(UART("/dev/ttyACM0", 115200))
# if CircuitPython or MicroPythom
rc = Roboclaw(UART(), address=0x80)

# Get version string
for x in range(0, 255):
    value = rc.write_eeprom(x, x * 2)
    print("EEPROM:")
    print(x)
    print(" ")
    if not value:
        print("Failed")
    else:
        print("Written")