コード例 #1
0
ファイル: drive.py プロジェクト: ckumpe/robot-inventor-tools
hub.speaker.beep()

motor = Motor('C')
motor.run_to_position(165)


def pen_up():
    motor.run_for_degrees(-90)


def pen_down():
    motor.run_for_degrees(90)


motor_pair = MotorPair('B', 'A')
motor_pair.set_default_speed(20)
motor_pair.set_motor_rotation(wheel_radius * 2 * math.pi, 'cm')

pen_down()

motor_pair.move_tank(axis_radius * math.pi * 2.05,
                     'cm',
                     left_speed=-25,
                     right_speed=25)

#pen_up()
#pen_down()

motor_pair.move(-pen_radius * 2, 'cm')
pen_up()
コード例 #2
0
# %%
print("Setting arm motors to position 0...")
motor_b = Motor('B')  # Left arm
motor_f = Motor('F')  # Right arm
motor_b.run_to_position(0)
motor_f.run_to_position(0)
print("DONE!")

# %% [markdown]
# # Configure motors

# %%
print("Configuring motors...")
motors_movement = MotorPair('A', 'E')
motors_movement.set_default_speed(80)
print("DONE!")

# %% [markdown]
# # Program color reactions

# %%
color_sensor = ColorSensor('C')

# %% [markdown]
# We will use a counter to control printing on the console.
# First, we need to initialize it.

# %%
ii = 0
コード例 #3
0
print("-"*15 + " Execution started " + "-"*15 + "\n")

# %%
hub = MSHub()
app = App()

# %%
hub.status_light.on('black')

# %% [markdown]
# # Configure motors

# %%
print("Configuring motors...")
motors_wheels = MotorPair('A', 'E')
motors_wheels.set_default_speed(70)

motor_left_arm = Motor('B') # Left arm
motor_right_arm = Motor('F') # Right arm

motor_left_arm.set_default_speed(40)
motor_right_arm.set_default_speed(-40)

motors_arms = MotorPair('B', 'F')
print("DONE!")

# %% [markdown]
# # Set arm motors to starting position
# This isn't part of the original program, but I think it is good practice to make sure motors always start in the same state.
#
コード例 #4
0
# %% [markdown]
#
# # Control motors
# We could initialize and control the motors individually.
# However, it can be very practical to pair them, which can be done as follows.

# %%
# Initialize motors.
print("Initializing motors...")
motor_pair = MotorPair('A', 'E')
print("DONE!")

# Set default speed.
speed = 80
print("Setting default speed to " + str(speed) + "...")
motor_pair.set_default_speed(speed)
print("DONE!")

# Move the motors.
amount = 40

# With steering, we can make the robot turn right (100),
# turn left (-100) or go straight (0)
steering = 100

print("Moving the motors by " + str(amount) + " cm and steering of " +
      str(steering) + "...")
motor_pair.move(amount, unit='cm', steering=steering)
print("DONE!")

# %% [markdown]