From 6b76e72b1bb92badb0c83b912a8a6d60ff8d3fe9 Mon Sep 17 00:00:00 2001 From: Cort Date: Thu, 25 Jan 2024 23:26:37 +0800 Subject: [PATCH] Add hsv support in pybricks --- public/arenaFrame.html | 2 +- public/index.html | 2 +- public/js/skulpt.js | 2 +- public/pybricks/ev3devices.py | 15 +++++++++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/public/arenaFrame.html b/public/arenaFrame.html index 3af57cf6..58d37e90 100644 --- a/public/arenaFrame.html +++ b/public/arenaFrame.html @@ -37,7 +37,7 @@ - + - + diff --git a/public/js/skulpt.js b/public/js/skulpt.js index e71fe56a..62000b77 100644 --- a/public/js/skulpt.js +++ b/public/js/skulpt.js @@ -14,7 +14,7 @@ var skulpt = new function() { './pybricks/parameters.py': 'pybricks/parameters.py?v=2db482b9', './pybricks/tools.py': 'pybricks/tools.py?v=20eafcfc', './pybricks/hubs.py': 'pybricks/hubs.py?v=7fa5cb11', - './pybricks/ev3devices.py': 'pybricks/ev3devices.py?v=7b453a67', + './pybricks/ev3devices.py': 'pybricks/ev3devices.py?v=8ee63a93', './pybricks/robotics.py': 'pybricks/robotics.py?v=bf287d71', './ev3dev2/Training_Wheels.py': 'ev3dev2/Training_Wheels.py?v=ad06cf56', }; diff --git a/public/pybricks/ev3devices.py b/public/pybricks/ev3devices.py index 388c1347..e58ab015 100644 --- a/public/pybricks/ev3devices.py +++ b/public/pybricks/ev3devices.py @@ -103,7 +103,7 @@ def run_time(self, speed, time, then=Stop.HOLD, wait=True): self.motor.speed_sp(speed) self.motor.time_sp(time / 1000) self.motor.stop_action(then) - + self.motor.command('run-timed') if wait: @@ -117,7 +117,7 @@ def run_angle(self, speed, rotation_angle, then=Stop.HOLD, wait=True): else: self.motor.position_sp(-rotation_angle) self.motor.stop_action(then) - + self.motor.command('run-to-rel-pos') if wait: @@ -128,7 +128,7 @@ def run_target(self, speed, target_angle, then=Stop.HOLD, wait=True): self.motor.speed_sp(abs(speed)) self.motor.position_sp(target_angle) self.motor.stop_action(then) - + self.motor.command('run-to-abs-pos') if wait: @@ -144,7 +144,7 @@ def dc(self, duty): elif duty < -100: duty = -100 self.run(duty * 1050 / 100) - + def track_target(self, target_angle): self.run_target(100, target_angle, then=Stop.COAST, wait=False) time.sleep(SENSOR_DELAY) @@ -184,6 +184,13 @@ def rgb(self): rgb[i] = rgb[i] / 2.55 return rgb + def hsv(self): + time.sleep(SENSOR_DELAY) + hsv = self.sensor.valueHSV() + for i in range(3): + hsv[i] = int(hsv[i]) + return hsv + class UltrasonicSensor: def __init__(self, port=None): self.sensor = simPython.UltrasonicSensor(port)