C++ is one of the most powerful programming languages and it’s suitable for a wide variety of uses. The RAD Studio, C++ Builder IDE is a simple development tool for those who want to develop C++ applications. Developing robots with a reliable C++ IDE is very important for beginners and professionals it is also important which language features exist, how to use them, how to start and end the program professionally. If you want to learn C++ by developing robots in C or C++ programming, please just download the latest C++ Builder.
The free version of C++ Builder CE is great for beginners. If you want to develop professionally it is highly recommended, you start with C++ Builder CE version. Today we have a great selection to choose from when looking for a free C++ IDE. Tools like C++ Builder CE, Dev-C++, and even the BCC32 command line compiler.
In this post, we will explain how to compile and run a C++ program with the Dev-C++, C++ Builder CE, and with C++ Builder.
Table of Contents
How to program a robot using C++ – Safety First !
Asimov’s Three Laws of Robotics
- Zeroth Law: A robot may not harm humanity, or, by inaction, allow humanity to come to harm.
- First Law: A robot may not injure a human being or, through inaction, allow a human being to come to harm.
- Second Law: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.
- Third Law: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
- Introduced in 1942 and later published in 1960’s I, Robot by Isaac Asimov.
- The first concept of AI and Robot safety and ethics. The book explores how these laws fail in practice.
Source: wikipedia.org/wiki/Three_Laws_of_Robotics
Zeroth Law: A robot may not harm humanity, or, by inaction, allow humanity to come to harm
When we develop a robot, first we should consider about the user and environment safety. A robot shouldn’t be harmful to anything. Otherwise you may injure someone, a system, or something in that environment. This is important because, a small problem may be result with unexpected problems. Interestingly, very simple robots may create various problems to harm user and environment, while they look simple and cute. Because of these, there are 4 main areas to consider; robot design in mechanical view, control system in electronic design and software in development. In addition to this, environment or environment design is important for the robot system too. These 4 areas should be primary to consider before we program a robot, this step may require thinking about a lot of variations and solving problems.
I have a very simple and harmful example in my life. We have cleaning robot at home, and it is really cute and helpful. I wasn’t expecting that this robot will grab the power cable and pull down my 8TB hard disk from the 1m height shelf of my cabinet. I had a tripod light and the data cable of my 8TB external disk was somehow connected to my desktop over this tripod. One day, when I was outside, our cleaning robot hit that tripod which fell down to the ground and the data cable grabbed my drive and then my 8TB hard drive to the ground. Luckily, there were few damages to the files and my hard disk was working. This drive was the backup of our 22 years of great memories of photos and videos of my family, including my son. I had more than 6 other different issues with this simple robot too. As in this case, very simple systems may cause unexpected problems. Thus, we should care about robots in mechanical, and electronic design, in software development also we should consider about their environment too.
From the software viewpoint, developers may think about these checks, and some precautions can be made by software development in parallel to mechanical and electronic designs. If you search in google, you can see many issues ranging from ‘smart’ cars to industrial robots, a chess robot to simple toy robots. Safety should be considered in all steps of development.
How to program a 2D robot using C++
2D Robot Movement : Let’s assume that we have a chess robot, and it has 2 motors to move in X and Y directions of the board. This example can be applied to the 3D printers, 2D laser engraving machines, 2D drawing robots, 2D validation robots, etc. too. If we want to move this robot, first we should set input to go a known position, this can be result of a chess engine or it can be from user input too. Here is a very simple example how the main structure of this application should be, in a simple way,
First, we should create functions to drive motors of the robot to move that the position. In this function, we should check safety in each step, we can check sensors and other external sensor inputs (peripherals, may be camera, microphone etc. too). Then we should send signals to rotate that motor. Generally, this is about sending voltage to the pins of the motor driver. Then we should check the position or if there is any situation to stop or to continue more. We should repeat this till the rotation of our motor is enough to position the same coordinate in real system. Here is a simplified function,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
int drive_motor(char N, int pos, int mov) { do { // check sensors for safety // if safe send signal to rotate motor N in CW or CCW direction // read position, check if it is rotating etc. // repeat till position is at mov }while(pos == mov); return pos; } |
next we should set the initial position and we should get some input; in our example, lets simply get input from the keyboard,
1 2 3 4 5 6 7 8 9 10 11 |
int inputX, inputY; // X,Y inputs to go that position int posX = 2; // X position of the robot arm int posY = 2; // Y position of the robot arm std::cout << "Enter Position X:"; std::cin >> posX; std::cout << "Enter Position Y:"; std::cin >> posY; |
and finally we should check if both inputs are in limits, if they are then we can rotate both motors with our drive functions.
1 2 3 4 5 |
if( (posX>0 && posX<8) && (posY>0 && posY<8) ) // check if input is in limits { posX = drive_motor(0, posX, inputX); // goto inputX position posY = drive_motor(1, posY, inputY); // goto inputY position } |
Is there a full example to how to program a 2D robot using C++
Here is a full example to move a 2D robot,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include <iostream> int drive_motor(char N, int pos, int mov) { do { // check sensors for safety // if safe send signal to rotate motor N in CW or CCW direction // read position, check if it is rotating etc. // repeat till position is at mov }while(pos == mov); return pos; } int main() { int inputX, inputY; // X,Y inputs to go that position int posX = 2; // X position of the robot arm int posY = 2; // Y position of the robot arm std::cout << "Enter Position X:"; std::cin >> posX; std::cout << "Enter Position Y:"; std::cin >> posY; if( (posX>=0 && posX<8) && (posY>=0 && posY<8) ) // check if input is in limits { posX = drive_motor(0, posX, inputX); // goto inputX position posY = drive_motor(1, posY, inputY); // goto inputY position } return 0; } |
In C++ Builder, Get-It has many components to use IoTs, to develop apps using sensors, manipulators and many peripherals. You can connect to robot machines via usb, wifi, Bluetooth or via other devices. C++ is a very popular language and most of the devices have libraries or components to do connections with them. Get-It has many components to do connection with peripherals. You can find many IoT components here
For example, MITOV Software Componnents allows you to do these kinds of connections, they released new versions of a lot of great components for the RAD Studio 11. Mitov Software is specialized in development of high-performance software and Data Flow solutions involving:
- Video Processing
- Audio Processing
- Digital Signal Processing
- Real Time Data Acquisition
- Communications
- Process Control
- Computer Vision
- Artificial Intelligence
- Data Visualization
- Visual Instrumentation
- Parallel and Grid Computing
- Hardware Control
Check these top 6 component packs available this year,
Although the free C++ Builder Community Edition is extremely powerful it is intended for students, beginners, and startups. If you are a regular business or do not qualify for the free community edition then you can download a free trial of the very latest full RAD Studio C++ Builder version.
C++ Builder is the easiest and fastest C and C++ IDE for building everything from simple to professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder an
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition