Coder Shah

LEGO Mindstorms 51515 Micropython programming tutorial

Recommended Posts

On 12/26/2020 at 6:38 PM, Gelo said:

Actually I just want to code in Python that Gelo walks.. 

https://www.antonsmindstorms.com/2021/01/27/python-motor-synchronization-coordinating-multiple-spike-or-mindstorms-motors/

On 1/25/2021 at 3:36 AM, malvinas2 said:

But is there anything available like an old-school documentation (pdf?) regarding Python and Mindstorms 51515 ? 

 

Share this post


Link to post
Share on other sites
On 1/28/2021 at 1:11 AM, Coder Shah said:

Thank 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)
 
    
 
Edited by Gelo

Share this post


Link to post
Share on other sites

Are there good video's or text tutorials out there that explain how to add joysticks and buttons to remote control with your phone or with a controller ( I have a ps4 controller )?

Share this post


Link to post
Share on other sites
1 hour ago, jovel said:

Are there good video's or text tutorials out there that explain how to add joysticks and buttons to remote control with your phone or with a controller ( I have a ps4 controller )?

https://antonsmindstorms.com/2021/07/17/how-to-remote-control-your-mindstorms-hub-with-an-android-app-in-python/

Anton's page is a good start to find many things about any Mindstorms (EV3, RI, ...) He has video's/explanation about most hubs how to remote control with phone/ps4 controller.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.