mirror of
https://github.com/pybricks/pybricks-projects.git
synced 2026-09-15 02:52:41 +00:00
sets/ev3/home/gripp3r: refactor main.py
This commit is contained in:
committed by
laurensvalk
parent
56b060f3c5
commit
bcb47f0d23
+1
-1
@@ -8,7 +8,7 @@
|
||||
"name": "Download and Run",
|
||||
"type": "ev3devBrowser",
|
||||
"request": "launch",
|
||||
"program": "/home/robot/${workspaceRootFolderName}/gripp3r.py",
|
||||
"program": "/home/robot/${workspaceRootFolderName}/main.py",
|
||||
"interactiveTerminal": false
|
||||
}
|
||||
]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Example LEGO® MINDSTORMS® EV3 Gripp3r Program
|
||||
|
||||
This program requires LEGO® EV3 MicroPython v2.0 downloadable at https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3.
|
||||
|
||||
Building instructions can be found at https://www.lego.com/en-us/themes/mindstorms/buildarobot.
|
||||
|
||||
You can drive Gripp3r around and make it grip or release objects by the IR beacon.
|
||||
@@ -1,21 +1,7 @@
|
||||
#!/usr/bin/env pybricks-micropython
|
||||
|
||||
"""
|
||||
Example LEGO® MINDSTORMS® EV3 Gripp3r Program
|
||||
---------------------------------------------
|
||||
|
||||
This program requires LEGO® EV3 MicroPython v2.0 downloadable at:
|
||||
https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3
|
||||
|
||||
Building instructions can be found at:
|
||||
https://www.lego.com/en-us/themes/mindstorms/buildarobot
|
||||
"""
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.ev3devices import Motor, TouchSensor, InfraredSensor
|
||||
from pybricks.media.ev3dev import SoundFile
|
||||
from pybricks.parameters import Button, Direction, Port, Stop
|
||||
from pybricks.tools import wait
|
||||
|
||||
from rc_tank_util import RemoteControlledTank
|
||||
|
||||
@@ -75,26 +61,3 @@ class Gripp3r(RemoteControlledTank):
|
||||
while Button.BEACON in \
|
||||
self.ir_sensor.buttons(channel=self.ir_beacon_channel):
|
||||
pass
|
||||
|
||||
def main(
|
||||
self,
|
||||
driving_speed: float = 1000 # mm/s
|
||||
):
|
||||
"""
|
||||
Gripp3r's main program performing various capabilities
|
||||
"""
|
||||
self.gripping_motor.run_time(
|
||||
speed=-500,
|
||||
time=1000,
|
||||
then=Stop.COAST,
|
||||
wait=True)
|
||||
|
||||
while True:
|
||||
self.drive_by_ir_beacon(speed=driving_speed)
|
||||
self.grip_or_release_by_ir_beacon(speed=500)
|
||||
wait(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
GRIPP3R = Gripp3r()
|
||||
GRIPP3R.main(driving_speed=1000)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env pybricks-micropython
|
||||
|
||||
|
||||
from pybricks.parameters import Stop
|
||||
from pybricks.tools import wait
|
||||
|
||||
from gripp3r import Gripp3r
|
||||
|
||||
|
||||
gripp3r = Gripp3r()
|
||||
|
||||
gripp3r.gripping_motor.run_time(
|
||||
speed=-500,
|
||||
time=1000,
|
||||
then=Stop.COAST,
|
||||
wait=True)
|
||||
|
||||
while True:
|
||||
gripp3r.drive_by_ir_beacon(speed=1000)
|
||||
gripp3r.grip_or_release_by_ir_beacon(speed=500)
|
||||
wait(1)
|
||||
Reference in New Issue
Block a user