コード例 #1
0
# This code is meant as a boilerplate for your remote control project.
# Connect to it using a steering wheel or app:
# https://play.google.com/store/apps/details?id=com.antonsmindstorms.mindstormsrc&hl=nl&gl=US

from projects.mpy_robot_tools.rc import (RCReceiver, L_STICK_HOR, L_STICK_VER,
                                         R_STICK_HOR, R_STICK_VER, L_TRIGGER,
                                         R_TRIGGER, SETTING1, SETTING2)
from projects.mpy_robot_tools.helpers import clamp_int
from mindstorms import MSHub, ColorSensor, Motor, DistanceSensor
from mindstorms.control import wait_for_seconds
import math

# Create your objects here.
rcv = RCReceiver(name="robot")
ma = Motor("A")
hub = MSHub()

# Write your program here.
while True:  # Forever
    if rcv.is_connected():
        speed, turn = rcv.controller_state(R_STICK_VER, R_STICK_HOR)
        if rcv.button_pressed(1):
            hub.speaker.beep()
        ma.start_at_power(clamp_int(speed))

    else:
        # Stop all motors when not connected
        ma.stop()
        print("Waiting for connection...")
        wait_for_seconds(0.3)  # async wait, better than sleep_ms
コード例 #2
0
# %%
motor_left_arm.run_to_position(60)
motor_right_arm.run_to_position(335)

# Hit that pedal, baby
print("Hitting the pedal...")
motors_wheels.move(3, unit='cm')
print("DONE!")

# %%
# Fire first drum blaster
print("Firing first drum blaster...")
motors_wheels.move(2.5, unit='cm', steering=-100)

for ii in range(0, 3):
    motor_right_arm.start_at_power(40)
    wait_for_seconds(0.12)
    motor_right_arm.start_at_power(-40)
    wait_for_seconds(0.12)
motor_right_arm.run_to_position(300, direction='shortest path')

motor_left_arm.run_for_seconds(0.5, speed=-100)
motor_left_arm.run_to_position(25, direction='shortest path')
print("DONE!")

# %%
# Fire second drum blaster
print("Firing second drum blaster...")
motors_wheels.move(5, unit='cm', steering=100)

for ii in range(0, 4):
コード例 #3
0
flw = Motor("A") # Front Right Wheel
frw = Motor("B")
blw = Motor("E")
brw = Motor("F")

light = 100
while 1:
    if rcv.is_connected():
        speed, turn, strafe = rcv.controller_state(R_STICK_VER, R_STICK_HOR, L_STICK_HOR)
        if rcv.button_pressed(1):
            light = 100
        if rcv.button_pressed(2):
            light = 50
        if rcv.button_pressed(3):
            light = 0
        if rcv.button_pressed(8):
            break
        ls.light_up_all(light)
        flw.start_at_power(clamp_int(-speed - turn - strafe))
        frw.start_at_power(clamp_int( speed - turn - strafe))
        blw.start_at_power(clamp_int(-speed + turn - strafe))
        brw.start_at_power(clamp_int( speed + turn - strafe))

    else:
        flw.start_at_power(0)
        frw.start_at_power(0)
        blw.start_at_power(0)
        brw.start_at_power(0)
        print("Waiting for connection...")
        wait_for_seconds(0.3)