bewegen
Deutsch   English   

2. MOVE ROBOT

 

 

YOU LEARN HERE...

 

the most important commands you can use to control your robot.

 

 

EXAMPLES

 

Example 1: Drive and turn
The robot should first drive forwards, then turn left and then drive forwards again for a short distance.

The lines of your programme are executed in sequence. The forward()command sets the robot to the ‘forward’ state delay(2000)specifies the time in milliseconds until the microprocessor issues the next left()command. This sets the robot to the ‘turn left’ state. During the 550 milliseconds, the robot turns approx. 90° to the left. It then moves forwards again for 2000 milliseconds before it receives the stop() command.

 

Program:

from callibot import *

forward()
delay(2000)
left()
delay(550)
forward()
delay(2000)
stop()
► Copy to clipboard

The angle of rotation that the robot covers in 550 milliseconds depends on the surface and, in particular, on the charge status of the batteries. If the robot moves too slowly and only rotates by a small angle, you must change the batteries. Also test the programme in simulation mode. Here the robot always turns exactly 90°.


 

Example 2: Doing several things at the same time
Although the following programme consists of a sequence of instructions that are executed one after the other, the robot can do several things at the same time. The robot moves forwards for 4 seconds and then backwards for 4 seconds. While travelling backwards, it switches the LEDs on and off.

The motors and the LEDs are controlled by the microprocessor, whereby the microprocessor can also operate several actuators simultaneously. While the motors are in the backward state after receiving the backward()command, the LEDs are switched on and off

setLED(1) switches the LEDs on. After 3000 ms setLED(0) switches the LEDs off. After a further 1000 ms, the motors receive the stop() command and the robot stops  

Program:

from callibot import *

forward()
delay(4000)
backward()
setLED(1)
delay(3000)
setLED(0)
delay(1000)
stop()
► Copy to clipboard

 

Example 3: Travelling on an arc
The robot should first travel on a left arc for 5 s, then on a right arc for 5 s and stop. Use the commands leftArc(r) or rightArc(r) for the arc, where the radius r is in metres.

You can change the speed with setSpeed(speed). You can select values between 0 and 100 as speed. The default speed is 50.

 

Program:

from callibot import *

setSpeed(30)
leftArc(0.2)
delay(5000)
rightArc(0.2)
delay(5000)
stop()
► Copy to clipboard

 

 

REMEMBER...

 

The following commands are available for controlling the robot:

 forward()  moves forwards
 backward()  moves backwards
 left()  turns left
 right()  turns right
 leftArc(r)  moves to left arc with radius r
 rightArc(r)  moves to right arc with radius r
 stop()  stops
 setSpeed(speed)  sets the speed (default 50)
 delay(ms)  remains in the same state for ms milliseconds
 setLED(1)  switch on LEDs
 setLED(0)  switch off LEDs
 setAlarm(1)  switches on a pip tone
 setAlarm(0)  switches the pip tone off

When programming robots, you have to think in terms of states. The forward() function sets the robot in a forward motion. While the motors are in this state, the microprocessor can issue commands to other actuators.

You can cancel a running programme at any time by switching off the power supply with the blue button on the back of the robot chassis.

 

 

TO SOLVE BY YOURSELF

 

 

1.

Create a course with some objects and write a programme so that the robot moves from the start to the finish.



 

2.

The robot should move along an arc to the left until it has travelled a complete circle. It should then move along a right-hand arc for the same length of time.

 

 

 

 

 

SUPPLEMENT: CONTROLLING MOTORS AND LEDs INDIVIDUALLY

 

The forward(), left() etc. commands control the entire running gear, which consists of two synchronised motors. However, you can also switch on the individual motors and control their speed. To do this, you must import the callibotmot library. With motL.rotate(speed)the left motor is set to forward motion and rotates at the speed speed. For positive speed values the motor rotates forwards, for negative values it rotates backwards and for speed = 0the motor stops. The motR.rotate(speed) command works in the same way for the right motor.

 

Example 4: The left motor first runs forwards for 2 seconds at a speed of 50 and stops. Then the right

motor runs backwards at a speed of 50 for 2 seconds and stops.

Program:

from callibotmot import *

motL.rotate(50)
delay(3000)
motL.rotate(-50)
delay(2000)
motL.rotate(0)
► Copy to clipboard


Example 5: Switching LEDs on and off individually

You can use the setLED(1) and setLED(0) commands to switch both LEDs on and off at the same time. You can also address the LEDs individually:
setLEDLeft(1) switches the left LED on
setLEDLeft(0) switches the left LED off
setLEDRight(1) switches the right LED on
setLEDRight(0)switches the right LED off

Your programme switches one LED on and the other off.

 


Program:

from callibot import *

setLEDLeft(1)
delay(2000)
setLEDLeft(0)
setLEDRight(1)
delay(2000)
setLEDRight(0)
► Copy to clipboard

 

 

TO SOLVE BY YOURSELF

 

 

4.

Let the two motors rotate forwards at the same speed for 4000 milliseconds.

5.

Run the left motor forwards and the right motor backwards for 4 seconds.

6.

How do you have to control the left and right motors so that the robot moves in a left-hand arc for 4 seconds?

7.

Complete example 3 so that when the robot is travelling on the left-hand arc, the left-hand LED lights up and when it is travelling on the right-hand arc, the right-hand LED lights up and the left-hand LED is switched off.