THIS IS THE TEST SITE OF EUROBRICKS!
-
LEGO Mindstorms 51515 Micropython programming tutorial
Gelo replied to Coder Shah's post in a topic in LEGO Technic, Mindstorms, Model Team and Scale ModelingThank you very much - I'll check this manual! Actually I've already found another solution and it works well. Gelo walks, stops and turns (see code below). I'm new to Mindstorms and coding, but am eager to hear feedback.. from random import randint from mindstorms import MSHub, Motor, MotorPair, DistanceSensor from mindstorms.control import wait_for_seconds, wait_until, Timer from mindstorms.operator import equal_to #Initialization hub = MSHub() motor_a = Motor('A') motor_b = Motor('B') motor_c = Motor('C') motor_d = Motor('D') motor_pair_1 = MotorPair('A', 'B') motor_pair_2 = MotorPair('C', 'D') distance_sensor = DistanceSensor('E') timer = Timer() power_a = 70 power_b = 70 #Running setting motor_a.run_to_position(270,'shortest path', power_b) motor_b.run_to_position(270,'shortest path', power_b) motor_c.run_to_position(90,'shortest path', power_b) motor_d.run_to_position(90,'shortest path', power_b) #Countdown hub.speaker.beep(60, 1) wait_for_seconds(0.5) hub.speaker.beep(60, 1) wait_for_seconds(0.5) hub.speaker.beep(60, 1) wait_for_seconds(0.5) hub.speaker.beep(90, 1) #Running while True: motor_pair_1.start(0, power_a) motor_pair_2.start(0, power_a) distance_sensor.wait_for_distance_closer_than(15, 'cm') motor_pair_1.stop() motor_pair_2.stop() wait_for_seconds(3) timer.reset() #Turning a = randint(0,1) if a == 0: #Right motor_a.run_to_position(140,'shortest path', power_b) motor_b.run_to_position(270,'shortest path', power_b) motor_c.run_to_position(220,'shortest path', power_b) motor_d.run_to_position(90,'shortest path', power_b) hub.motion_sensor.reset_yaw_angle() while hub.motion_sensor.get_yaw_angle() < 90: motor_pair_1.start(0, power_a) motor_pair_2.start(0, power_a) else: #Left motor_a.run_to_position(270,'shortest path', power_b) motor_b.run_to_position(40,'shortest path', power_b) motor_c.run_to_position(90,'shortest path', power_b) motor_d.run_to_position(320,'shortest path', power_b) hub.motion_sensor.reset_yaw_angle() while hub.motion_sensor.get_yaw_angle() > -90: motor_pair_1.start(0, power_a) motor_pair_2.start(0, power_a) motor_pair_1.stop() motor_pair_2.stop() #Running setting motor_a.run_to_position(270,'shortest path', power_b) motor_b.run_to_position(270,'shortest path', power_b) motor_c.run_to_position(90,'shortest path', power_b) motor_d.run_to_position(90,'shortest path', power_b) wait_for_seconds(3)
-
LEGO Mindstorms 51515 Micropython programming tutorial
Gelo replied to Coder Shah's post in a topic in LEGO Technic, Mindstorms, Model Team and Scale ModelingThank you! I tried with the "super" variable but unfortunately it does not work. (TypeError) Actually I just want to code in Python that Gelo walks..
-
LEGO Mindstorms 51515 Micropython programming tutorial
Gelo replied to Coder Shah's post in a topic in LEGO Technic, Mindstorms, Model Team and Scale ModelingThank you for the tutorial! Do you know how to start 4 motors at the same time? Unfortunately I just found the "motor_pair" to control 2 motors.. motor_pair = MotorPair('A', 'B')
Sponsored Links