Solutions to today’s tasks:
Program the robot to lift its arm by 90 degrees in 1 second.
from hub import port
import runloop
import motor, time
async def main():
# write your code here
# Start motor
motor.run(port.D, 90)
# Wait for 2 seconds
time.sleep_ms(1000)
# Stop motor
motor.stop(port.D)
runloop.run(main())
Program the robot to lift its arm by 90 degrees in 2 seconds.
from hub import port
import runloop
import motor, time
async def main():
# write your code here
# Start motor
motor.run(port.D, 45)
# Wait for 2 seconds
time.sleep_ms(2000)
# Stop motor
motor.stop(port.D)
runloop.run(main())
Program your robot to hand you its cup using the "run_for_time()" command.
from hub import port
import runloop
import motor
async def main():
# write your code here
await motor.run_for_time(port.D, 2000, 45)
runloop.run(main())
Use everything you have learned so far to program the robot to move toward you and then lift the cup.
from hub import port
import time
import runloop
import motor
async def main():
# write your code here
motor.run(port.A, 1000)
motor.run(port.B, -1000)
time.sleep_ms(2000)
motor.stop(port.A)
motor.stop(port.B)
await motor.run_for_time(port.D, 1000, 90)
runloop.run(main())