In this tutorial, you will find the tools you need to easily connect to your robots, and a variety of options for programming and controlling them. Interfacing LEGO MINDSTORMS robots with Raspberry Pi is made easy thanks to the Ch Mindstorms Controller (CMC). The C-STEM Center at UC Davis has developed C-STEM Studio with CMC to provide a simple-to-use platform for 4- to 19-year-old students to learn Computing, Science, Technology, Engineering, and Maths with LEGO MINDSTORMS NXT and EV3 robots.
This article was written by Binsen Qian and appears in The MagPi #63.
C-STEM Studio is a user-friendly platform that allows you to control LEGO MINDSTORMS NXT and EV3 robots directly from a Raspberry Pi. A single program can also control multiple NXT/EV3 robots at the same time. This tutorial will guide you through the steps of installing the software, connecting to your robots, and controlling them.
- C-STEMbian OS
- A monitor or display
- MINDSTORMS NXT/EV3 robots (up to seven)
In order to connect to your MINDSTORMS robot from the Ch Mindstorms Controller, you will need access to the C-STEM Studio platform. We recommend downloading and installing C-STEMbian, a free open-source Linux operating system for Raspberry Pi. C-STEMbian is a superset of Raspbian, and includes several tools that provide a user-friendly environment for computing, robotics, and cyber-physical systems.
If your Raspberry Pi is already running Raspbian, you can install the C-STEM software modules individually. All the necessary software, including C-STEMbian, is available from the C-STEM website, along with instructions to guide you through the installation process, and to help you connect to your Raspberry Pi.
Connecting to your MINDSTORMS robot(s)
Connecting to your MINDSTORMS robot is simple with the C-STEM software.
Open C-STEM Studio and launch the Ch Mindstorms Controller. Ch Mindstorms Controller can connect with both EV3 and NXT robots. Simply press the Scan Robot button, then add the robots that are found to the list on your robot manager. Follow the instructions on screen to pair the robots with your Raspberry Pi, and add the robots you want to work with. Do make sure that the robots are turned on and have Bluetooth enabled.
Once the robots have been scanned and added to the list, select the ones you would like to connect to and press Connect. Robots to which you are connected will have a green dot next to their names.
Controlling your MINDSTORMS robots
Once you are connected to your robot, the CMC offers many options for control:
Using the Motion Control panel, you can rotate individual motors continuously, move motors by given angles, and drag and drop motors into a desired angle. You can also set the speed of each motor at any time.
Monitor sensor data
Use the Sensors panel to monitor the sensors attached to the robot. You can set sensors to different modes, and the values from the sensors will update automatically.
In the other panels we introduced some educational features, designed to help students learn mathematical concepts. For example, in the Vehicle Control panel, a student controls a robot configured as a vehicle. Students can set the vehicle’s wheel size and speed, and drive the vehicle by distance, by angle, or by time. The robot then drives as programmed, and a graph of distance versus time is plotted. With these features, students can learn about number lines, linear relationships, and the concept of pi.
Program robots in C/C++ interpreter Ch
To program the robots, you need to keep them connected in the controller, then open ChIDE and start programming. You can program up to seven robots, which is hard to do using other platforms.
#include CMindstorms robot1, robot2, robot3, robot4; CMindstormsGroup group; double radius = 1.1; // radius of the wheels (inches) double trackWidth = 4.54; // track width of the robots (inches) /* add the four robots as members of the group */ group.addRobot(robot1); group.addRobot(robot2); group.addRobot(robot3); group.addRobot(robot4); group.driveDistance(5, radius); // drive robots forward 5 inches group.turnLeft(90, radius, trackWidth); // turn robots left 90 degrees group.driveDistance(10, radius); //drive robots forward 10 inches