Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__/
*.pyc

# Visual Studio Code files
.vscode/
24 changes: 24 additions & 0 deletions robots/DINOR3X/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# DINOR3X

> Designed by Lasse Stenbæk Lauesen
>
> This charming robotic triceratops dinosaur is capable of walking and turning on all fours.

The build instructions may be found at the official LEGO MINDSTROMS site [here](https://www.lego.com/cdn/cs/set/assets/bltad10c02978864265/DINOR3X.pdf).

Please add a Color Sensor to Dinor3x's back or tail. Control DINOR3X as follows:

- Make DINOR3X roar by pressing the IR Remote Control's Beacon button

- Make DINOR3X walk or turn according to instructions from the IR Beacon
- 2 top/up buttons together: walk forward
- 2 bottom/down buttons together: walk backward
- Top Left / Red Up: turn left on the spot
- Top Right / Blue Up: turn right on the spot
- Bottom Left / Red Down: stop
- Bottom Right / Blue Down: calibrate to make the legs straight

- Make DINOR3X change its speed when detecting some colors
- Red: walk fast
- Green: walk normally
- White: walk slowly
Binary file added robots/DINOR3X/T-rex roar.wav
Binary file not shown.
213 changes: 213 additions & 0 deletions robots/DINOR3X/dinor3x.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#!/usr/bin/env python3


from ev3dev.ev3 import (
Motor, LargeMotor, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C,
TouchSensor, ColorSensor, InfraredSensor, RemoteControl,
INPUT_1, INPUT_3, INPUT_4,
Sound
)


class Dinor3x:
FAST_WALK_SPEED = 800
NORMAL_WALK_SPEED = 400
SLOW_WALK_SPEED = 200

def __init__(
self,
jaw_motor_port: str = OUTPUT_A,
left_motor_port: str = OUTPUT_B, right_motor_port: str = OUTPUT_C,
touch_sensor_port: str = INPUT_1, color_sensor_port: str = INPUT_3,
ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1):
self.jaw_motor = MediumMotor(address=jaw_motor_port)

self.left_motor = LargeMotor(address=left_motor_port)
self.right_motor = LargeMotor(address=right_motor_port)

self.touch_sensor = TouchSensor(address=touch_sensor_port)
self.color_sensor = ColorSensor(address=color_sensor_port)

self.ir_sensor = InfraredSensor(address=ir_sensor_port)
self.remote_control = RemoteControl(sensor=self.ir_sensor,
channel=ir_beacon_channel)

self.speaker = Sound()

self.roaring = False
self.walk_speed = self.NORMAL_WALK_SPEED

def roar_by_ir_beacon(self):
"""
Dinor3x roars when the Beacon button is pressed
"""
if self.remote_control.beacon:
self.roaring = True
self.open_mouth()
self.roar()

elif self.roaring:
self.roaring = False
self.close_mouth()

def change_speed_by_color(self):
"""
Dinor3x changes its speed when detecting some colors
- Red: walk fast
- Green: walk normally
- White: walk slowly
"""
if self.color_sensor.color == ColorSensor.COLOR_RED:
self.speaker.speak(text='RUN!')
self.walk_speed = self.FAST_WALK_SPEED
self.walk(speed=self.walk_speed)

elif self.color_sensor.color == ColorSensor.COLOR_GREEN:
self.speaker.speak(text='Normal')
self.walk_speed = self.NORMAL_WALK_SPEED
self.walk(speed=self.walk_speed)

elif self.color_sensor.color == ColorSensor.COLOR_WHITE:
self.speaker.speak(text='slow...')
self.walk_speed = self.SLOW_WALK_SPEED
self.walk(speed=self.walk_speed)

def walk_by_ir_beacon(self):
"""
Dinor3x walks or turns according to instructions from the IR Beacon
- 2 top/up buttons together: walk forward
- 2 bottom/down buttons together: walk backward
- Top Left / Red Up: turn left on the spot
- Top Right / Blue Up: turn right on the spot
- Bottom Left / Red Down: stop
- Bottom Right / Blue Down: calibrate to make the legs straight
"""
# forward
if self.remote_control.red_up and self.remote_control.blue_up:
self.walk(speed=self.walk_speed)

# backward
elif self.remote_control.red_down and self.remote_control.blue_down:
self.walk(speed=-self.walk_speed)

# turn left on the spot
elif self.remote_control.red_up:
self.turn(speed=self.walk_speed)

# turn right on the spot
elif self.remote_control.blue_up:
self.turn(speed=-self.walk_speed)

# stop
elif self.remote_control.red_down:
self.left_motor.stop(stop_action=Motor.STOP_ACTION_HOLD)
self.right_motor.stop(stop_action=Motor.STOP_ACTION_HOLD)

# calibrate legs
elif self.remote_control.blue_down:
self.calibrate_legs()

def calibrate_legs(self):
self.left_motor.run_forever(speed_sp=100)
self.right_motor.run_forever(speed_sp=200)

while self.touch_sensor.is_pressed:
pass

self.left_motor.stop(stop_action=Motor.STOP_ACTION_HOLD)
self.right_motor.stop(stop_action=Motor.STOP_ACTION_HOLD)

self.left_motor.run_forever(speed_sp=400)

while not self.touch_sensor.is_pressed:
pass

self.left_motor.stop(stop_action=Motor.STOP_ACTION_HOLD)

self.left_motor.run_to_rel_pos(
position_sp=-0.2 * 360,
speed_sp=500,
stop_action=Motor.STOP_ACTION_HOLD)
self.left_motor.wait_while(Motor.STATE_RUNNING)

self.right_motor.run_forever(speed_sp=400)

while not self.touch_sensor.is_pressed:
pass

self.right_motor.stop(stop_action=Motor.STOP_ACTION_HOLD)

self.right_motor.run_to_rel_pos(
position_sp=-0.2 * 360,
speed_sp=500,
stop_action=Motor.STOP_ACTION_HOLD)
self.right_motor.wait_while(Motor.STATE_RUNNING)

self.left_motor.reset()
self.right_motor.reset()

def walk(self, speed: float = 1000):
self.calibrate_legs()

self.left_motor.run_forever(speed_sp=-speed)
self.right_motor.run_forever(speed_sp=-speed)

def turn(self, speed: float = 1000):
self.calibrate_legs()

if speed >= 0:
self.left_motor.run_to_rel_pos(
position_sp=180,
speed_sp=speed,
stop_action=Motor.STOP_ACTION_HOLD)
self.left_motor.wait_while(Motor.STATE_RUNNING)

else:
self.right_motor.run_to_rel_pos(
position_sp=180,
speed_sp=-speed,
stop_action=Motor.STOP_ACTION_HOLD)
self.right_motor.wait_while(Motor.STATE_RUNNING)

self.left_motor.run_forever(speed_sp=speed)
self.right_motor.run_forever(speed_sp=-speed)

def close_mouth(self):
self.jaw_motor.run_timed(
speed_sp=-200,
time_sp=1000,
stop_action=Motor.STOP_ACTION_COAST)

def open_mouth(self):
self.jaw_motor.run_timed(
speed_sp=200,
time_sp=1000,
stop_action=Motor.STOP_ACTION_COAST)

def roar(self):
self.speaker.play(wav_file='/home/robot/sound/T-rex roar.wav')

self.jaw_motor.run_timed(
speed_sp=-200,
time_sp=0.5 * 1000,
stop_action=Motor.STOP_ACTION_COAST)
self.jaw_motor.wait_while(Motor.STATE_RUNNING)

self.jaw_motor.run_timed(
speed_sp=200,
time_sp=0.5 * 1000,
stop_action=Motor.STOP_ACTION_COAST)
self.jaw_motor.wait_while(Motor.STATE_RUNNING)

def main(self):
self.close_mouth()

while True:
self.roar_by_ir_beacon()
self.change_speed_by_color()
self.walk_by_ir_beacon()


if __name__ == '__main__':
DINOR3X = Dinor3x()
DINOR3X.main()
Binary file added robots/GRIPP3R/Air release.wav
Binary file not shown.
Binary file added robots/GRIPP3R/Airbrake.wav
Binary file not shown.
10 changes: 10 additions & 0 deletions robots/GRIPP3R/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# GRIPP3R

> The GRIPP3R robot is constructed for some heavy-duty lifting. It’s got the muscle to grab and drop a can of soda with its powerful grasping grippers.

Control GRIPP3R as follows:

- Make GRIPP3R drive around by the IR Remote Control's blue and red buttons
- Make GRIPP3R grip or release an object by pressing the IR Remote Control's Beacon button

The build instructions may be found at the official LEGO MINDSTROMS site [here](https://www.lego.com/cdn/cs/set/assets/blt3cf20feda579587c/31313_GRIPP3R_2016.pdf).
71 changes: 71 additions & 0 deletions robots/GRIPP3R/gripp3r.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3


from ev3dev.ev3 import (
Motor, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C,
TouchSensor, INPUT_1, INPUT_4,
Sound
)
from ev3dev.helper import RemoteControlledTank

from multiprocessing import Process


class Gripp3r(RemoteControlledTank):
def __init__(
self,
grip_motor_port: str = OUTPUT_A,
left_motor_port: str = OUTPUT_B, right_motor_port: str = OUTPUT_C,
touch_sensor_port: str = INPUT_1,
ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1):
super().__init__(
left_motor=left_motor_port, right_motor=right_motor_port,
polarity='normal')

self.grip_motor = MediumMotor(address=grip_motor_port)

self.touch_sensor = TouchSensor(address=touch_sensor_port)

self.speaker = Sound()

def grip_or_release_by_ir_beacon(self):
while True:
if self.remote.beacon:
if self.touch_sensor.is_pressed:
self.speaker.play(wav_file='Air release.wav')

self.grip_motor.run_timed(
speed_sp=500,
time_sp=1000,
stop_action=Motor.STOP_ACTION_BRAKE)
self.grip_motor.wait_while(Motor.STATE_RUNNING)

else:
self.speaker.play(wav_file='Airbrake.wav')

self.grip_motor.run_forever(speed_sp=-500)

while not self.touch_sensor.is_pressed:
pass

self.grip_motor.stop(stop_action=Motor.STOP_ACTION_BRAKE)

while self.remote.beacon:
pass

def main(self):
self.grip_motor.run_timed(
speed_sp=-500,
time_sp=1000,
stop_action=Motor.STOP_ACTION_BRAKE)
self.grip_motor.wait_while(Motor.STATE_RUNNING)

Process(target=self.grip_or_release_by_ir_beacon,
daemon=True).start()

super().main()


if __name__ == '__main__':
GRIPP3R = Gripp3r()
GRIPP3R.main()
Binary file added robots/SPIK3R/Blip 3.wav
Binary file not shown.
12 changes: 12 additions & 0 deletions robots/SPIK3R/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPIK3R

> This six-legged creature doesn’t just look like a scorpion, it also acts like one. It turns sharply, snaps with it’s crushing claw, and it’s lightning tail is ready to fire at anyone or anything that gets in its way.

Control SPIK3R as follows:

- Make SPIK3R move straight forward by pressing the IR Remote Control's two Up buttons at the same time
- Make SPIK3R turn right by pressing the IR Remote Control's Right Up button
- Make SPIK3R sting by pressing the IR Remote Control's Beacon button
- Make SPIKER pinch by pressing the Touch Sensor (please do connect one to enable this)

The build instructions may be found at the official LEGO MINDSTROMS site [here](https://www.lego.com/cdn/cs/set/assets/blt7dca5180ea66ea5e/31313_SPIK3R_2016.pdf).
Loading