From ea171507f79a91f20dc381aaac5d6f9de92e32f2 Mon Sep 17 00:00:00 2001 From: ElTentakel Date: Tue, 8 Feb 2022 20:37:24 +0100 Subject: [PATCH 1/4] Add Technic Control+ Angular Motors --- bricknil/const.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bricknil/const.py b/bricknil/const.py index 261a99b..aae8f10 100644 --- a/bricknil/const.py +++ b/bricknil/const.py @@ -64,5 +64,7 @@ class Color(Enum): 0x003A: 'Powered Up Hub IMU Gyro', 0x003B: 'Powered Up Hub IMU Position', 0x003C: 'Powered Up Hub IMU Temperature', + 0x004B: 'Technic Control+ Medium Angular Motor', + 0x004C: 'Technic Control+ Large Angular Motor', } From 6d856a507ff342fb771c76a3b91af43cf4281ece Mon Sep 17 00:00:00 2001 From: ElTentakel Date: Tue, 8 Feb 2022 20:46:25 +0100 Subject: [PATCH 2/4] add Technic Control Plus Large Angular motors --- bricknil/sensor/motor.py | 70 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/bricknil/sensor/motor.py b/bricknil/sensor/motor.py index c52a922..75fe06b 100644 --- a/bricknil/sensor/motor.py +++ b/bricknil/sensor/motor.py @@ -291,7 +291,7 @@ class ExternalMotor(TachoMotor): """ _sensor_id = 0x26 - + 0x004C: 'Technic Control+ Angular Motor', class CPlusLargeMotor(TachoMotor): """ Access the Technic Control Plus Large motors @@ -363,6 +363,74 @@ class CPlusXLMotor(TachoMotor): _sensor_id = 0x2F +class CPlusMediumAngularMotor(TachoMotor): + """ Access the Technic Control Plus Medium Angular motors + + These are similar to the :class:`InternalMotor` with build-in tachometer and + sensor for sending back the motor's current speed and position. You + don't need to use the sensors, and can treat this as strictly an + output. + + Examples:: + + # Basic connection to the motor on Port A + @attach(CPlusMediumAngularMotor, name='motor') + + # Report back when motor speed changes. You must have a motor_change method defined + @attach(CPlusMediumAngularMotor, name='motor', capabilities=['sense_speed']) + + # Only report back when speed change exceeds 5 units, and position changes (degrees) + @attach(CPlusMediumAngularMotor, name='motor', capabilities=[('sense_speed', 5), 'sense_pos']) + + And then within the run body:: + + await self.motor.set_speed(50) # Setting the speed + await self.motor.ramp_speed(80, 2000) # Ramp speed to 80 over 2 seconds + await self.motor.set_pos(90, speed=20) # Turn clockwise to 3 o'clock position + await self.motor.rotate(60, speed=-50) # Turn 60 degrees counter-clockwise from current position + + See Also: + * :class:`TrainMotor` for connecting to a train motor + * :class:`InternalMotor` for connecting to the Boost hub built-in motors + + """ + + _sensor_id = 0x4C + +class CPlusLargeAngularMotor(TachoMotor): + """ Access the Technic Control Plus Large Angular motors + + These are similar to the :class:`InternalMotor` with build-in tachometer and + sensor for sending back the motor's current speed and position. You + don't need to use the sensors, and can treat this as strictly an + output. + + Examples:: + + # Basic connection to the motor on Port A + @attach(CPlusLargeAngularMotor, name='motor') + + # Report back when motor speed changes. You must have a motor_change method defined + @attach(CPlusLargeAngularMotor, name='motor', capabilities=['sense_speed']) + + # Only report back when speed change exceeds 5 units, and position changes (degrees) + @attach(CPlusLargeAngularMotor, name='motor', capabilities=[('sense_speed', 5), 'sense_pos']) + + And then within the run body:: + + await self.motor.set_speed(50) # Setting the speed + await self.motor.ramp_speed(80, 2000) # Ramp speed to 80 over 2 seconds + await self.motor.set_pos(90, speed=20) # Turn clockwise to 3 o'clock position + await self.motor.rotate(60, speed=-50) # Turn 60 degrees counter-clockwise from current position + + See Also: + * :class:`TrainMotor` for connecting to a train motor + * :class:`InternalMotor` for connecting to the Boost hub built-in motors + + """ + + _sensor_id = 0x4C + class TrainMotor(Motor): """ Connects to the train motors. From e5929b2b60abbff82d2f49cc700dc066eb95db11 Mon Sep 17 00:00:00 2001 From: ElTentakel Date: Tue, 8 Feb 2022 20:50:09 +0100 Subject: [PATCH 3/4] fix copy paste error in motor.py --- bricknil/sensor/motor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bricknil/sensor/motor.py b/bricknil/sensor/motor.py index 75fe06b..0a64164 100644 --- a/bricknil/sensor/motor.py +++ b/bricknil/sensor/motor.py @@ -291,7 +291,7 @@ class ExternalMotor(TachoMotor): """ _sensor_id = 0x26 - 0x004C: 'Technic Control+ Angular Motor', + class CPlusLargeMotor(TachoMotor): """ Access the Technic Control Plus Large motors From 1050a3a000ab86fa712c471f2fd7a375394d995b Mon Sep 17 00:00:00 2001 From: ElTentakel Date: Tue, 8 Feb 2022 20:51:36 +0100 Subject: [PATCH 4/4] fix _sensor_id of Medium Angular Motor --- bricknil/sensor/motor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bricknil/sensor/motor.py b/bricknil/sensor/motor.py index 0a64164..a56c32d 100644 --- a/bricknil/sensor/motor.py +++ b/bricknil/sensor/motor.py @@ -395,7 +395,7 @@ class CPlusMediumAngularMotor(TachoMotor): """ - _sensor_id = 0x4C + _sensor_id = 0x4B class CPlusLargeAngularMotor(TachoMotor): """ Access the Technic Control Plus Large Angular motors