Deutsch English |
YOU LEARN HERE... |
|
EXAMPLES |
Example 1:
Drive and turn Der Roboter soll zuerst vorwärts fahren, dann links abbiegen und danach wieder ein kurzes Stück vorwärts fahren.
Program: from mbrobot import * #from mbrobot_plus import * forward() delay(2000) left() delay(550) forward() delay(2000) stop() We refrain from displaying the import line for the Maqueen Plus V2 in all programme examples. If you are working with this model, the import line is from mbrobot_plusV2 import * |
Program: from mbrobot import * #from mbrobot_plus import * forward() delay(4000) backward() setLED(1) delay(3000) setLED(0) delay(1000) stop() With the Maqueen Plus, the LEDs can also light up in other colours (1:red, 2:green, 3:yellow, 4:blue, 5:pink, 6:cyan, 7:white) |
Program: from mbrobot import * #from mbrobot_plus import * setSpeed(40) leftArc(0.2) delay(5000) rightArc(0.2) delay(5000) stop() |
REMEMBER YOU... |
The following commands are available for controlling the robot:
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 abort a running programme at any time by setting the small switch on the back of the robot chassis to ‘OFF’. |
TO SOLVE BY YOURSELF |
|
SUPPLEMENT: CONTROLLING MOTORS AND LEDs INDIVIDUALLY |
The forward(), left() etc. commands control the entire running gear, which consists of two motors. However, you can also switch on the individual motors and control their speed. 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 = 0 the motor stops. The motR.rotate(speed) command works in the same way for the right-hand motor. |
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. If you look closely at the circuit board of your robot, you will see that the left LED is labelled LED-L and the right LED is labelled LED-R. You can also address the LEDs individually: For the mbRobot, use the following commands:
Program: from mbrobot import * ledLeft.write_digital(1) ledRight.write_digital(0) delay(600) ledLeft.write_digital(0) ledRight.write_digital(1) delay(600) ledLeft.write_digital(1) ledRight.write_digital(0) delay(600) ledLeft.write_digital(0) With the Maqueen Plus and Maqueen PlusV2, you can switch the LED individually with the following commands: Program: from mbrobot_plus import * from mbrobot_plusV2 import * setLEDLeft(1) setLEDRight(0) delay(600) setLEDLeft(0) setLEDRight(1) delay(600) setLEDLeft(2) setLEDRight(0) delay(600) setLEDLeft(0) setLEDRight(2) delay(600) setLEDRight(0) Example 6: RGB LEDs (Maqueen Plus V2 only)
Program: from mbrobot_plusV2 import * repeat 3: setRGB(0, 255, 0, 0) delay(1000) setRGB(1, 0, 255, 0) delay(1000) setRGB(2, 0, 0, 255) delay(1000) setRGB(3, 255, 0, 255) delay(1000) clearRGB() |
TO SOLVE BY YOURSELF |
|