Jython
Deutsch   English 

19. Maqueen Mechanic

New TigerJython (Version 2.28) required.

 


 
Mechanic Loader
 
Mechanic Beatle

 

The Loader can load and transport small objects. The Beatle can pick up light objects with a gripper arm and move them to any desired location. The required components with a servo motor can be ordered individually (Maqueen Mechanics Loader, Maqueen Mechanic Beatle) or in a kit (Maqueen Mechanics Roboter-Kit). The servomotor is connected to port S1 or S2 of the Maqueen 4 or Maqueen Plus. The older Maqueen model does not have such an S interface.

 

 

On the Maqueen Plus V2, the servomotors are connected to port P1 or P2. These are located at the rear right of the chassis. In the programme, the servo ports must be called up in the setServo() command with P1 or P2 (instead of S1 or S2)..

 

 

 


  Mechanic Loader

The loader can be assembled according to the following construction plan: Construction Loader

Beispiel 1: Move loader with servomotor
The servomotor first moves the loader to the starting position (down), then the bucket is moved upwards and after 2000 milliseconds back down to the starting position.

The servomotor is moved with the command setServer(port, angle). Execute the programme below with different angles to find out for which value the blade is in the initial position (bottom). The angles depend on the position in which the servomotor was before the blade was screwed on.

 

from mbrobot_plus import *
#from mbrobot import*

setServo("S1", 160)
delay(2000)
setServo("S1", 100)
delay(2000)          
setServo("S1", 160)
► Copy to clipboard

Explanations of the program code:

setServer("S1", 160) The servomotor is connected to port S1. The second parameter specifies the position of the servomotor.


Example 2
: Position the loader with ultrasonic sensor
The robot is to load an object that is located near a vertical wall and transport it away. It uses the ultrasonic sensor to measure the distance to the wall.

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

Explanations of the program code:

d = getDistance() The distance to the wall is measured in an "endless" loop.
setServo("S1", 100) Picks up the object.

 


  Mechanic Beatle

The gripper arm can be assembled according to the following instructions: Construction Beatle

Example 3: Grasp object
The servomotor moves both arms of the gripper arm simultaneously. With the command
setServo("S1", 60)
into the open position, with
setServo("S1", 95)
the robot can grab objects. The angle may need to be adjusted.

The robot moves to the object located a short distance in front of it, grabs it with its gripper arm, moves back a short distance, turns to the left and places the object in the new location (similar to the video below).


from mbrobot import *
#from mbrobot_plus import *

setServo("S1", 95)
delay(1000)
setServo("S1", 60)
forward()
delay(1000)
stop()
setServo("S1", 95)
backward()
delay(500)
left()
delay(700)
stop()
setServo("S1", 60)
► Copy to clipboard

Explanations of the program code:

setServer("S1", 60) The gripper arm should be in the open position. This angle may need to be adjusted. Depending on the size of the object, the angle 95° must also be adjusted.


Example 4
: Positioning the gripper arm with an ultrasonic sensor
The robot is to load an object that is located near a vertical wall and transport it away. It uses the ultrasonic sensor to measure the distance to the wall.

from mbrobot import *
#from mbrobot_plus import *

setServo("S1", 60)
forward()
repeat:
    d = getDistance()
    print(d)
    if d < 20: 
        stop()
        delay(500)
        setServo("S1", 95)
        delay(500)             
        backward()
        delay(2500)
        left()
        delay(700)      
        stop()
        setServo("S1", 60)
    delay(100)  
► Copy to clipboard

Explanations of the program code:

getDistance() Measures the distance to the wall every 100 milliseconds


Example 5
: Turn ultrasonic sensor with servomotor
The ultrasonic sensor can be moved with a second servomotor. This is connected to port S2. The rotating ultrasonic sensor can be used to search for objects (task 3) or to follow a wall at a certain distance (task 4).

The ultrasonic sensor is rotated at right angles from a frontal position. First in one step and then in small steps.

from mbrobot import *
#from mbrobot_plus import *

setServo("S2", 90)
delay(2000)
setServo("S2", 0)
delay(2000)
setServo("S2", 90)
delay(2000)

angle = 90
while angle >= 0:
    setServo("S2", angle)
    delay(500)
    angle = angle - 10
    
angle = 0
while angle <= 90:
    setServo("S2", angle)
    delay(500)
    angle = angle + 10 
► Copy to clipboard

Explanations of the program code:

setServo("S2", 90) Turn the servomotor so that the ultrasonic sensor is in the frontal position. If this is not the case, you can adjust the angle or unscrew the sensor short and place the round base so that the sensor can then be screwed on exactly frontally.
setServo("S2", 0) bzw. setServo("S2", 180) Turns the sensor parallel to the direction of travel.

 


Exercises:


1)


Robot with a loader or a gripper arm moves forwards for 2000 milliseconds and picks up an object. It then moves backwards for 2000 milliseconds, turns approx. 90° to the left, moves forwards for 2000 milliseconds and puts the object down.

 


2)


Supplement the situation from task 1 with two vertical walls so that the robot completes each forward movement with the help of the distance sensor and repeats the loading and unloading process several times.

 


3)


The ultrasonic sensor rotates in small steps with the help of the servomotor until it recognises an object. It then triggers an alarm. You can restrict the search by only searching for objects at a distance of between 30 and 70 cm.



4)


With the help of a servomotor, the ultrasonic sensor turns to a position parallel to the direction of travel so that it can measure the distance sideways. The robot then moves forwards at a distance of approximately 15 cm along a straight wall and continuously corrects its direction of travel.