CC++C++17Game DevelopmentLearn C++

How To Program A Robot Using C++

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 CEDev-C++, and even the BCC32 command line compiler.

How To Program A Robot Using C++? RAD Studio 11.2 image.

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.

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,

next we should set the initial position and we should get some input; in our example, lets simply get input from the keyboard,

and finally we should check if both inputs are in limits, if they are then we can rotate both motors with our drive functions.

Is there a full example to how to program a 2D robot using C++

Here is a full example to move a 2D robot,

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

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
CC++C++17Introduction to C++Learn C++

How To Run A C++ Program In The Linux Terminal

C++C++17Game DevelopmentLearn C++

How To Program A Game In C++

C++C++17Introduction to C++Language FeatureLearn C++

What Is C++ Programming Used For?

C++C++17Introduction to C++Language FeatureLearn C++

How To Run A C++ Program