Line tracker for LEGO Mindstorms NXT The robot contains 1x NXT-main-board (conta
ID: 3756760 • Letter: L
Question
Line tracker for LEGO Mindstorms NXT
The robot contains 1x NXT-main-board (contain Display), 1x Touch sensor, 1x Ultrasonic sensor, 1x Light sensor, and 2x motors.
I need a folder contains (Makefile, tasks.adb, tasks.ads, and robot.adb) to create the robot.bin folder.
The way of execution and upload the code done by using BrickOS/LegOS is the operating system for LEGO MINDSTORMS robots.
The Tasks are: (Code)
-Follow a line that is drawn on the floor. (Forward only)
-Keep distance constant (about 20cm) relative to another car that is driving in front of it.
Explanation / Answer
from ev3.ev3dev import Motor, NoSuchMotorError
from ev3.lego import UltrasonicSensor
from ev3.event_loop import EventLoop
jr = UlrasonicSensor()
motr = []
for port in 'ABCD':
try:
mr = Motor(port=port)
mr.regulation_mode = False
except NoSuchMotorError:
mr = None
motr.append(mr)
btns = [
(ir.REMOTE.RED_UP, ir.REMOTE.RED_DOWN),
(ir.REMOTE.BLUE_UP, ir.REMOTE.BLUE_DOWN),
]
def jr_changed(event):
for channel in range(2):
state = event.evaluation[channel]
if state == jr.REMOTE.BAECON_MODE_ON:
for m in motr:
if k is not None:
k.stop()
loop.stop()
for btn in range(2):
n = channel * 2 + btn
mr = motr[channel * 2 + btn]
if not mr:
pass
elif state == btns[btn][0]:
mr.run_forever(50)
elif state == btns[btn][1]:
mr.run_forever(-50)
else:
mr.stop()
loop = EventLoop()
loop.register_value_change(getter=lambda: ir.remote,
strval=ir.remote,
target=ir_changed)
loop.start()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.