How To Program A Lego Mindstorm Ev3
First of all, I'm new for this and I need a little help! I have a LEGO Mindstorms EV3 robot, I downloaded (LEGO Mindstorms EV3 Home Edition) to control the EV3.
BALANC3R (left) and Gyro Boy (right) This tutorial will show you how to build and program a self-balancing LEGO MINDSTORMS EV3 robot that can drive around a room. You can build and program BALANC3R (left) or Gyro Boy (right). Once your robot is up and running, you’ll be challenged to customize the construction and program to invent your own self-balancing robot. Step 1: Building a robot To begin, choose the robot you want to build, and follow the respective step-by-step building instructions. Requirements for BALANC3R:.
1x. 1x Gyroscopic Sensor.
Click to build BALANC3R Requirements for Gyro Boy:. 1x LEGO MINDSTORMS EV3 Education Core Set #45544. Click to build Gyro Boy Step 2: Installing the EV3 Gyro Sensor block If you’re using the LEGO MINDSTORMS EV3 Home Edition Software, you’ll need to install the EV3 Gyro Sensor block before you can program your robot. Follow the steps in to install the block.
If you’re using the LEGO MINDSTORMS EV3 Student Edition, this block is already installed. Installing new Sensor blocks Step 3: Download the balancing robot project.
Right-click, click “Save Link As,” and save the project file to your computer. Launch the EV3 programming software, and open the downloaded project file. Before you run the programs, let’s briefly examine how they work.
The project includes four example programs, two for each robot:. BALANC3R-Basics: Balance in place, turn right, and turn left. BALANC3R-RemoteControl: Control the robot with the infrared remote. GyroBoy-Basics: Balance in place, turn right, and turn left. GyroBoy-AvoidObstacles: Drive around while avoiding obstacles Each program consists of two configuration blocks, a balance loop, and a drive control loop, as shown in the figure below. The balancing program consists of a balance loop, a drive control loop, and configuration blocks. The configuration blocks let you specify what the robot looks like, so that the robot knows how to balance.

For example, the second setting of the first setting specifies the diameter of the robot’s wheels. The example programs come preconfigured with the correct settings for BALANC3R and Gyro Boy if you use the LEGO EV3 Gyro Sensor. If you use the NXT HiTechnic Gyro, change the Choose Sensor setting on the Initialize My Block to 1.
The balance loop keeps the robot balanced. It measures and calculates the position and speed of the motors, and it determines the robot’s angular velocity (how fast it’s falling), as well as the robot’s angle relative to the ground. In turn, it uses this sensor information to calculate how to drive the motors in order to keep the robot up right. You won’t need to change any setting of the blocks in this loop. The drive control loop controls the speed and steering of the robot as it drives around a room using a simplified move block. This is the part of the program that you can easily customize to create your own program. Step 4: Running the basic example program You are now ready to download the example program to your robot.
If you’ve built BALANC3R, begin with BALANC3R-Basics. If you’ve built Gyro Boy, begin with GyroBoy-Basics. To start the program:. Hold the robot upright with its wheels on the ground.
Do not hold it tightly, but hold it loosely so that it’s just between falling forward and falling backward. Select the program and start it with the center button on the EV3 brick. You’ll first hear one beep. Keep holding the robot in place. You’ll then hear a double beep.
Now release the robot and let it balance. Your robot should now repeatedly balance in place for 7 seconds, turn right for 7 seconds, and turn left for 7 seconds. Follow these steps if the robot doesn’t balance:. If it doesn’t work on the first try, repeat the steps above a few times. After a while, you’ll know which is the correct “upright” starting position. Do not try to “help” the robot balance.
Of course you should catch the robot before it falls, but trying to keep it upright with your hands is counter-effective. Verify that the cables have been plugged correctly according to the building instructions:. The two Large motors should be connected to ports A and D.
(If you’ve accidentally interchanged them, that’s fine. The robot will confuse left and right turns, but balancing is unaffected.). The Gyro Sensor should be connected to input port 2, regardless of which sensor you use. Verify that you’ve mounted the Gyro Sensor correctly according to the building instructions.
Verify that the batteries are fresh. Verify that you are using the (1.06H or 1.06E as of this writing). Step 5: Running the second example program If you’ve successfully programmed your robot in the previous step, it’s easy to try out the other example program for your robot.
The robot balances in exactly the same way, but the robot’s movements are a little more interesting:. BALANC3R-RemoteControl lets you control BALANC3R with the infrared remote, as shown in the video above. Just press the buttons on the remote to make the robot drive forward, backward, and turn.
(You’ll figure out the controls quickly.) If you don’t press any buttons, the robot just balances in the same place. GyroBoy-AvoidObstacles makes Gyro Boy drive around a room while backing up from obstacles, as shown in the video above. Before you run the program, make sure that the white beams of both the robot’s arms point downward. The program relies on this starting position to make sure the Ultrasonic Sensor doesn’t detect the floor as an ‘obstacle’ when the robot’s left arm points downward. Step 6: Customizing the program As you’ve learned earlier, the balance loop keeps the robot balanced while the drive control loop controls the robot’s speed and steering. The two loops run simultaneously, or at the same time. In the drive control loop, you use the Move My Block to specify the robot’s speed and steering, as shown below.
The Move block makes the robot drive and steer. In this configuration, the robot drives forward (30) while turning to the left (-15).
The robot keeps driving or turning at the specified rate until you run the block again with different values for speed and steering. The figure below shows the Move My Block in action in the basic example program you ran in step 4. The first Move block sets both steering and speed to 0, which makes the robot balance in place without turning. Next, a Wait block pauses the loop for 7 seconds, keeping the robot in the same place. Then, a second Move block sets the steering value to 20, making the robot turn to the right. After another 7 second wait, the robot starts tuning left by setting the steering value to -20.
Controlling the robot with Move My Blocks in the drive control loop Now that you’ve learned how to control the robot, it’s time to put your skills to the test with programming challenges. To solve these challenges, you can use the techniques from the, presented throughout chapters 1-9.
Instead of using Move Steering blocks in On mode as in the example programs, you use Move My Blocks as shown above. Challenges for BALANC3R:. Make your robot drive around a room while avoiding obstacles with the Infrared Sensor in Proximity mode. Make your robot follow the Infrared Beacon. As you move the beacon around, the robot should follow you. Attach the Color Sensor in front of the robot’s wheels, and make the robot follow a line. You can print line following tracks for your robot from.
Challenges for Gyro Boy:. Make your robot drive in different directions based on the color it detects with the Color Sensor. To accomplish this, make the robot wait for the sensor to see either a yellow, red, green, or blue object. Then, make it drive in a certain direction for 3 seconds based on the detected color, before waiting for a new color signal.
Make your robot show different types of faces/eyes on the screen as you interact with its sensors. Show an angry face if you press the Touch Sensor, show a happy face when you trigger the Color Sensor, and so on. Step 7: Making your own balancing robot In the previous steps, you’ve made BALANC3R or Gyro Boy balance on two wheels, and you learned to control it with the Move My Block. Now that you’ve got the essential components working, you’re ready to customize both your robot and your program. For example, you can turn BALANC3R into a life-like humanoid with arms, and make it talk to you. Or, go crazy and make any EV3 vehicle balance on its rear wheels.
What about a self-balancing? Whatever you make, let others know in the comments below. Happy building!
Step 8: Further reading In order to make this tutorial accessible for everyone with an EV3 set, I didn’t cover the details of the balancing algorithm. Rather, the design of this program makes it possible to control the robot even if you don’t know exactly how the balancing mechanism works. However, many papers have been written about self-balancing robots, and I encourage you to read more on the subject as you explore the details of the EV3 program provided on this page. The balancing algorithm in this program is based on a, which provides a good overview of the subject, along with Java source code that implements the balancing algorithm.
In turn, this paper relies on the design and algorithm used in the, which you can study for further detail. Hello, Followed the building instruction for Banlanc3r, updated my firmware to 1.06E, downloaded your code into EV3. Checked everything twice!
When I start both program for Balanc3r, I hear the single beep, then the two ones and then; the motor connected to port A goes -100% (backward)power continuous while the other is idle. Do you have any hint on what can be wrong? ———————- Hi, Forget about my previous mail My gyro was dead 🙁, tried with a new one and all works now. No I need to tune the parameters BR Al. I did not want to tear my car down so I used sensors and motors from my NXT kit. To make the Balanc3r work, I had to rearrange a few items in your building instructions.
When I executed the program, got the one beep, then 2 beeps and then the Robot started to balance, waited for 7 secs and then went straight forward at high speed, fell down and then stopped with “ERROR” showing on the screen. Before delving into your program for learning,I will try your program using the formul3r car as the robot. If this fails, then I will finish reading your book and try building the robot according to your instructions. Thanks for posting this, I’m rather new to mindstorms. I’ve ben working on translating the HiTechnic balancing bot program(NXT-G) to (EV3-G).
I’ll keep working on it and compare it to your program (which works great!!) and see if one is better than the other. Thanks again!!!!!!!!!!!!!!
P.S I tried your program with a bot like the Educator bot made from #31313, and a different bot of my own design and it still worked!!!! Is it okay if I post the link to here on Mindstorms Community and pics of your bot? As I have only one large motor is available for now, I made a single motor but 2 wheels robot base on BALANCE3R with small change on robot structure and program. It is able to keep stand stable and move forward/backward, but it cannot steer (of course it cannot).
It is my first self-balance robot. Thanks Laurens! One question, the ReadEncoder block contains one parameter 57.3. What this value means? Does it depending on robot structure?
The robot is higher and bigger than BALANCE3R do I need to change this value? Thanks for a good program in EV3 language. After re-reading your answers and directions again, I finally got your balancing robot to run. I run my robot on a rectangular (3ft by 6 ft) board with 4 inch walls. What I want to do is lower the ev3 Sensor from the top of the robot down near the wheels. Any idea if this will work without adjusting any of your parameters. Next point is that I want to build the balancing robot using the VEX Cortex system.
I believe that I can make a bigger robot using your code (robotc). I like to program in “C” type code. Your book was a big help in getting me going with the EV3 system. Hi Brian, That’s correct. I didn’t use the Color Sensor in the example program, but the program was designed in such a way that you can add such features yourself. I encourage you to look at the basic GyroBoy program to start with.
You can use the Color Sensor to make the robot drive in different directions (Using the light blue Move blocks) when it sees different colors. All of the balancing happens in the background, so you won’t have to worry about it.
To begin, try modyfing the wait blocks in the drive control loop. Currently, they wait for 7 seconds before changing the speed with the Move block. You could modify these Wait blocks to wait for a specific color, using Color mode. In this way, the robot will, for example, drive forward until it sees red, rather than driving forward for 7 seconds. Hi Laurens, You did a great job! I’ve downloaded your EV3 code and realized that you’ve implemented both robots with support of 3 gyro sensors: – Lego – Dexter Industries – HiTechnic I’ve reviewed difference in the EV3 code between all three sensors.
It seems that all differences are in a GyroRate block where for: – Lego and Dexter Industries sensors you use gyro rate as is – HiTechnic sensor you take raw value from gyro and divide on -4 Why am I explaining all this? Because I have an AbsoluteIMU-ACG gyro from Mindsensors. Thus I want to adopt (if necessary) your EV3 code to make BALANC3R with this gyro work. I remember that one of your first balancing robots was built with AbsoluteIMU-ACG gyro. Perhaps, you can provide coefficients that are specific for Mindsensors gyro? Or should it work as Lego and Dexter Industries gyro out of the box?
Thanks in advance, Andrey. As I’ve seen with some, I built BALANC3R but kept getting ERROR on the brick after it ran quickly and fell over. I tried a dozen times or more with no success. I double check my build and firmware versions and all was correct.
Then, out of the blue it worked once – I was so excited! What I learned over time is that the ERROR message occurs whenever the robot cannot find its sense of balance.
For me, it is a very delicate procedure to place the robot at just the right position (every so slightly leaning backwards from an equilibrium position), so that when it starts running it balances itself. Also, I delicately hold it upright with the slightest amount of pressure, so as not to hinder its movement when it starts under its own power. Now that I’ve practiced, I can get it going correctly about 90% of the time. Hi Laurens, I built and tried the GyroBoy and it works great. First I had forgotten to import the sensor blocks which resulted in a number of errors listed above: ERROR, fast moving backward (in my case), Importing and activating the sensor blocks and restarting LabView took care of that. I’ve been looking at your code and come across variables(?) in grey programming blocks. The palette shows the standard blocks (green, yellow, blue, red, etc) but no grey blocks.
Can you tell me where they come from? Thanks in advance. Kind regards, Frank. Hi Laurens, Ordered your book on march 19th (Standaard Boekhandel), got a message on march 30th that it had been sent (was on order from the distributor that long).
Got another message on april 2nd that it had been returned damaged. Now still awaiting delivery (grinding teeth).
By no means your fault of course. Just to illustrate that patience is a virtue 😉 Anywho. We (Overpelt Lego Builders Club in association with KWB Koersel) had a build and show weekend a week ago where I showed the Gyroboy. Very well received! Eyecatcher and many questions. Thanks for the excellent project! Hello, i have build Balanc3r using nxt motors set but with an ev3 brick and lego gyro.
That means i had to modify the design, since the nxt motors are different in terms of both holes and axle alignment. I tried to maintain the sensor on the same vertical as the wheel axes, and the center of the brick on the wheel axle also. I am using 62.4×20 diameter tires so i set that up on the program (still trying to source some 43.2×22’s and rims for them). I have fresh batteries. I ditched the IR sensor for now, and disabled the move code.
Basically i should have a Balanc3r that stands in place. The robot is started laying down, so the gyro is not drifting. I can also post some photos of it. Every time i start the robot, it goes in only one direction (depending on how good i balanced it) and then goes ERROR. I have built the light sensor segway with a fair bit of success with the same makeshift lego set, but this one with the gyro is not as successful.
Any suggestions i could try (tune the parameters?)? Hi, I’ve been going through your balance loop because I like to figure out how things work and I must say that I am very impressed. I am currently trying to build a robot that balances on one wheel with the help of the my blocks you created here. There is one particular piece of the program that I simply can’t wrap my head around and was wondering if you could help. That is, the ReadGyro block. I simply don’t understand what’s going on at the beginning of the code and why.
The following is the main question I have. What does the ‘mean’ variable represent? I tried for so long and couldn’t understand why the mean subtracted from the current value gives the angular velocity. I thought the value outputted from the GyroRate block was the angular velocity itself. If you could shed some light on this I would really appreciate it.
Thanks and always a fan 🙂. My Gyro boy will not balance and the programming I am using is the one you linked. Once I stand him up and release after the second beep nothing happens except for him falling over and saying error I was super excited to build this but am not getting very frustrated. I have gone through all of the things that may be wrong but he just doesn’t seem to be working and I have followed all the instructions please help I need this robot to work for a huge school project and i was certain it was but now it is completely failing. PLEASE REPLY! Also, don’t forget to download and install the driver (or block) for the gyro sensor from the Mindstorms website as per the instructions in Step 2 above.
Without the driver installed, the robot will never work, whatever you try. And, I find that the support (Gyro-Boy building instructions steps 1 through 17) helps real well to keep the robot up right when starting the program. As Fred said: the robot needs to be at its equilibrium when starting the program. It is at this time that the position of the gyro-sensor is zeroed. If this happens when the robot is e.g. Leaning forward (even only one degree) the robot will always try to adjust deflections to that zero position, which is leaning forward. This will always end up in an ERROR status.
Hi, i’m trying to get the Balanc3r with infrared remote control an extra ultrasone and Button sensor to make noise when someone comes close or say something when you push on the button. But now it looks the balancing functions can’t keep up and the robot falls. Is there a way to let them work together or is the processor not quick enough to calculated all the code? When i watched the NXTway-GS balancing robot i noticed that is drives much faster then the balanc3r, is this possible with EV3 or not? Thanx in advance, Allan. Hi, I am retired from a technical profession and I discovered Lego and Mindstrom thanks to you book, with a lot of fun both for me and my grand children.
Thank you for your very interesting site! I have built Gyroboy and made some modifications: I have changed the position of the color detector so that it allows gyroboy to walk on a table without falling out of it. See here: I also added the IR sensor to be able to drive Gyroboy.
Program Lego Mindstorms Ev3
Nevertheless, I tried to change the beep before the driving loop on your program example to have Gyroboy say: “Let’s go now!”, but it seems that it interrupts the balancing loop too long, because it makes it fall most of the times. Is there a way to do this without interrupting the loop too long?
Lego Mindstorm Ev3 Program
Hi, I’m a researcher in robotics and AI and I am interested in using this as part of my research, it’s a very well built controller! I only have two questions that I don’t understand about the code used, if you don’t mind giving me some info? 1) When getting the motor speed and motor position values, you divide both by 57.3. Is this just a constant? Otherwise, what is the purpose of that number?
Program Lego Mindstorms Ev3
2) When you get the angular rate and use it in the running average, you use dt x 0.2. Why do you multiply it by 0.2? Thanks a lot!