From 63aeed776e0259ec6c070a5f5c83b4ded51e9d9e Mon Sep 17 00:00:00 2001 From: Kaelin Laundry Date: Wed, 18 Mar 2020 19:26:44 -0700 Subject: [PATCH 1/4] Add simple Brickpi3 example --- platform/brickpi3-motor-and-sensor.py | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 platform/brickpi3-motor-and-sensor.py diff --git a/platform/brickpi3-motor-and-sensor.py b/platform/brickpi3-motor-and-sensor.py new file mode 100644 index 0000000..7bbbdc5 --- /dev/null +++ b/platform/brickpi3-motor-and-sensor.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +""" +The Brickpi3 doesn't support auto-detecting motors and sensors. To use devices +connected to the LEGO ports, you must specify what type of device it is. +""" + +from time import sleep +from ev3dev2 import list_devices +from ev3dev2.port import LegoPort +from ev3dev2.motor import OUTPUT_A, LargeMotor, SpeedPercent +from ev3dev2.sensor import INPUT_1 +from ev3dev2.sensor.lego import UltrasonicSensor + +p1 = LegoPort(INPUT_1) +# http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/brickpi3.html#brickpi3-in-port-modes +p1.mode = 'ev3-uart' +# http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/sensors.html#supported-sensors +p1.set_device = 'lego-ev3-us' + +pA = LegoPort(OUTPUT_A) +# http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/brickpi3.html#brickpi3-out-port-modes +pA.mode = 'tacho-motor' +# http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/motors.html#supported-motors +pA.set_device = 'lego-ev3-l-motor' + +# allow for some time to load the new drivers +sleep(0.5) + +s = UltrasonicSensor(INPUT_1) +m = LargeMotor(OUTPUT_A) + +print("Running motor...") + +while True: + dist = s.distance_centimeters + if dist < 50: + m.on(SpeedPercent(30)) + else: + m.on(SpeedPercent(-30)) \ No newline at end of file From 65371f0a144087b5da7fdd06fb7dc35c07bc0e43 Mon Sep 17 00:00:00 2001 From: Kaelin Laundry Date: Wed, 18 Mar 2020 19:27:29 -0700 Subject: [PATCH 2/4] newine --- platform/brickpi3-motor-and-sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/brickpi3-motor-and-sensor.py b/platform/brickpi3-motor-and-sensor.py index 7bbbdc5..0df90cd 100644 --- a/platform/brickpi3-motor-and-sensor.py +++ b/platform/brickpi3-motor-and-sensor.py @@ -37,4 +37,4 @@ if dist < 50: m.on(SpeedPercent(30)) else: - m.on(SpeedPercent(-30)) \ No newline at end of file + m.on(SpeedPercent(-30)) From 068078ba0de5d9507b4215bdf527abc3eaf42ee4 Mon Sep 17 00:00:00 2001 From: Kaelin Laundry Date: Wed, 18 Mar 2020 20:56:09 -0700 Subject: [PATCH 3/4] minor updates --- platform/brickpi3-motor-and-sensor.py | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 platform/brickpi3-motor-and-sensor.py diff --git a/platform/brickpi3-motor-and-sensor.py b/platform/brickpi3-motor-and-sensor.py old mode 100644 new mode 100755 index 0df90cd..0b0cb08 --- a/platform/brickpi3-motor-and-sensor.py +++ b/platform/brickpi3-motor-and-sensor.py @@ -38,3 +38,5 @@ m.on(SpeedPercent(30)) else: m.on(SpeedPercent(-30)) + + sleep(0.05) From c26b218027110fa36c6144d33a1829f136ea5681 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 19 Mar 2020 17:26:08 -0500 Subject: [PATCH 4/4] Update brickpi3-motor-and-sensor.py `set_device` on output port is not supported --- platform/brickpi3-motor-and-sensor.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/platform/brickpi3-motor-and-sensor.py b/platform/brickpi3-motor-and-sensor.py index 0b0cb08..aa59811 100755 --- a/platform/brickpi3-motor-and-sensor.py +++ b/platform/brickpi3-motor-and-sensor.py @@ -2,7 +2,9 @@ """ The Brickpi3 doesn't support auto-detecting motors and sensors. To use devices -connected to the LEGO ports, you must specify what type of device it is. +connected to the input ports, you must specify what type of device it is. +Output ports are pre-configured as NXT Large motors and do not need to be +configured manually. """ from time import sleep @@ -18,12 +20,6 @@ # http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/sensors.html#supported-sensors p1.set_device = 'lego-ev3-us' -pA = LegoPort(OUTPUT_A) -# http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/brickpi3.html#brickpi3-out-port-modes -pA.mode = 'tacho-motor' -# http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/motors.html#supported-motors -pA.set_device = 'lego-ev3-l-motor' - # allow for some time to load the new drivers sleep(0.5)