Skip to content

Instantly share code, notes, and snippets.

@marclennox
Last active February 25, 2022 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marclennox/fc4cc4b95562713b06b6e41451380f38 to your computer and use it in GitHub Desktop.
Save marclennox/fc4cc4b95562713b06b6e41451380f38 to your computer and use it in GitHub Desktop.
from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math
# Create your objects here.
tricky = MSHub()
movement_motors = MotorPair('A','B')
distance_sensor = DistanceSensor('D')
lifting_arm = Motor('C')
# Write your program here.
tricky.speaker.beep()
lifting_arm.run_to_position(5,'shortest path',10)
# Set the default speed and start moving until we sense the ball is close (7cm)
# You can replace 'shortest path' with 'clockwise' or 'counterclockwise'
movement_motors.set_default_speed(30)
movement_motors.start()
distance_sensor.wait_for_distance_closer_than(7,'cm')
# Stop moving and lift the ball into the air
movement_motors.stop()
lifting_arm.run_to_position(270,'shortest path',10)
# Spin tricky around fast and then slower
movement_motors.move(20,'cm',60)
movement_motors.move_tank(20,'cm',50,30)
#move motors by rotation:
"""lifting_arm.run_for_rotations(1,50)
"""
#move motor by seconds:
"""
lifting_arm.run_for_seconds(3,-100)
"""
#move motors by degrees:
"""
lifting_arm.run_for_degrees(90,80)
"""
#set motor default speed:
"""
lifting_arm.set_default_speed(50)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment