-
Notifications
You must be signed in to change notification settings - Fork 5
2.5 Tutorials on using the Control Blocks
We can use a raspberry pi running CAIT to control LEGO robots. If you haven't done so, please follow the LEGO setup Wiki pages to connect CAIT to the LEGO hubs. Once you have finished setting up the connection, you can control LEGO motors using the program shown below.
Note that the initialize control block appears differently from the other initialize blocks. This is because you need to tell the program which LEGO hubs you are using to initialize the control module. There is a CAIT mechanism that automatically scans the LEGO hubs available nearby. You can decide which hubs to add to your program through add hub blocks. In the program above, we are using one EV3 hub.
After you run the program, you should observe that the motor connected to port A of the EV3 hub with an IP address of 172.20.1.73 should move at a speed of 100 for 1 second.
Since CAIT can initialize more than one LEGO hub in the same program, therefore, you can create very complicated robots that use multiple EV3 and Robot Inventor hubs to control a large number of motors. The program below shows you how to control different motors attached to different hubs in a program.
Note that to control more LEGO Hubs simultaneously, you need to add more add hub blocks to the initialize control block. After adding the desired hubs into the program, you can use the control motor block to select which hub and which motor to control. You will find two types of motor block in the Control category. One is for the EV3 motor, and one is for the Robot Inventor motor. You can only use the EV3 motor in the control motor block if you selected an EV3 Hub in the block, and vice versa for a Robot Inventor motor.
After you run the program, you should see the motors connected to the corresponding hubs start to rotate.
If your robot build contains serval motors that need to run together, you will need to use motor groups. The program below shows you how to control two motors that are connected to different LEGO hubs to run simultaneously.
After you run the program, you should observe that the motors are moving together at a speed of 100 for 2 seconds.