|
Example 1: Testing the functionality of the servomotor
The servomotor first moves the loader to the starting position (bottom), then the bucket is rotated upwards and returns to the starting position after 2000 milliseconds.
With the setServo("S1 ’, 160) command, the servomotor rotates to the position with a rotation angle of 160°. S1 is the connection port. Execute the programme below with different angles between 0 and 180° to find out for which value the blade is in the starting position (down). |
|
|
|
from mbrobot_plus import *
#from mbrobot import*
setServo("S1", 160)
delay(2000)
setServo("S1", 100)
delay(2000)
setServo("S1", 160)
►Copy to clipboard
Example 2: Positioning the loader with an ultrasonic sensor
The robot should charge an object that is located near a vertical wall and transport it away (similar to the video above). To measure the distance to the wall, use the ultrasonic sensor
|
from mbrobot_plus import *
#from mbrobot import *
setServo("S1", 160)
setSpeed(20)
forward()
repeat:
d = getDistance()
print(d)
if d < 12:
stop()
delay(1000)
setServo("S1", 100)
setSpeed(20)
backward()
delay(4000)
stop()
setServo("S1", 160)
delay(100)
►Copy to clipboard
The distance to the wall is scanned in an ‘endless’ repeat loop every 100 milliseconds. If it is less than 12 cm, the object is charged.
|