Skip to content

Commit

Permalink
Add hsv support in pybricks
Browse files Browse the repository at this point in the history
  • Loading branch information
QuirkyCort committed Jan 25, 2024
1 parent c1ccaa3 commit 6b76e72
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion public/arenaFrame.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</main>

<script src="js/robotComponents.js?v=d160963e"></script>
<script src="js/skulpt.js?v=4439881d"></script>
<script src="js/skulpt.js?v=2dae2692"></script>
<script>
function readGET(name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
<script src="js/ev3dev2_generator.js?v=5889a0b7"></script>
<script src="js/pybricks_generator.js?v=13a33c1a"></script>
<script src="js/blockly.js?v=5c013597"></script>
<script src="js/skulpt.js?v=4439881d"></script>
<script src="js/skulpt.js?v=2dae2692"></script>
<script src="js/worlds/World_Base.js?v=9f07f537"></script>
<script src="js/worlds/world_Grid.js?v=3ed03b45"></script>
<script src="js/worlds/world_LineFollowing.js?v=8e36de6c"></script>
Expand Down
2 changes: 1 addition & 1 deletion public/js/skulpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand Down
15 changes: 11 additions & 4 deletions public/pybricks/ev3devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6b76e72

Please sign in to comment.