RealBasic: Robot A.I. – Part 1


The next series of articles will give a brief initiation in Robotic Artificial Intelligence. We’ll build a simulation of a robot with sensors. At first it will have no intelligence at all. But in the upcomming weeks we’ll learn it some tricks like finding the shortest path within a maze or house, handle closed passage ways and recalculate a new path to its destination. In another article we’ll learn the robot to find its location within a known map when it is dropped at an unknown location. Some exciting stuff!

But we’ll have to start at the beginning: building our robot Robby 🙂

Robby will have a couple of depth sensors (in reality these can be e.g. Kinect Depth cameras). They are placed on Robby so the robot can ‘feel’ everywhere around itself. They also have a limited range so Robby can only ‘see’ a limited distance. Robby is not a superhero, he cannot see through walls.
Robby changes to a red color when he is close to a wall, and colors green when he is at a safe distance.

Example of Robby:

You can see the robot, its sensors and a circle showing the range of the sensors.

In our first program, Robby is just like remote driven toy. We can go forward, turn left and turn right (with the cursor keys).

A framework will be build so we can later expand this program and even create other types of robots, sensors, etc…

Here is the layout of the framework:

ABSpace: This will hold our entry point to the world of robotics. It will describe the real world: what is the space Robby is walking in, where are the robots, etc…
Sensors: A simulation of sensors that can be attached to a robot. They can do measurements that the Robot A.I. can use.
Robots: A simulation of different types of robots that.
Global: Some classes we’ll need like Points, Maps, etc…

ABSpace is build like a movie with several frames. The steps we take are:

1. Initalize our space (give it a map, initialize our robot
2. Calculate a step (let all the sensors do measurements, calculate the new postition of the robot, let the Robot A.I. do it’s stuff)
3. Draw it so we’ll see the progress of our robots and what they have measured
4. Check if we’ll given some input to our robot (move, turn, etc)
5. Repeat from step 2

Here is a video to show what Robby Version 1 can do:

You can download the full source code at:
http://www.gorgeousapps.com/Rob1.zip

In the next part we’ll let Robby find the shortest path to a point on our map.

Happy programming!

Click here to Donation if you like my work

Advertisements

About Alwaysbusy

My name is Alain Bailleul and I'm the Senior Software Architect/Engineer at One-Two. I like to experiment with new technologies, Computer Vision and A.I. My projects are programmed in B4X , Xojo, C#, java, HTML, CSS and JavaScript. View all posts by Alwaysbusy

4 responses to “RealBasic: Robot A.I. – Part 1

  • Bill

    Very very cool! I haven’t gone through the code, but it took me a while to realize I had to click in the canvas to get it to recognize the key presses…at least on the Mac. It doesn’t look like you have to in your demo video on Windows, though.

    Anyway, in cmdStart.Action, I added at the end:
    self.Canvas1.SetFocus

    That way it’s ready to go right away. Thanks for this!

  • Alwaysbusy

    Hi Bill,

    It must have been a coincidence on windows. I needed it also in the upcoming articles.It’s probably good practice to set the focus to the canvas after pressing the button anyway. Thanks for pointing this out!

    Alwaysbusy

  • tim

    As a slight forward question, when commanding hardware, are all instructions necessarily sequential or some type of multithreading simulation achieveable, as in moving while turning (with proper mechanics provided)?

    There’s nothing like this on the web. Thanks

    • Alwaysbusy

      Indeed, ideally you wouldn’t give the commands sequentially.

      However, if you do, you could add some ‘smoothing’ to the algorithms (like bezier curves) and then if the steps are small enough sequential commanding works. I like to think our simulated robot here has one ball as a wheel with no friction.

      But in reality you should give several commands simultaneously.
      You would ‘buffer’ the commands for each motor and then do them at the same time via multithreading. Let each thread handle one motor. Let it wait for a ‘GO’ command. In a squential loop make all the calculations needed for each motor (thread). Give the ‘GO’ command and restart the sequence.

      0. Calculate our target
      1. Motor A: make the needed calculations to turn x degrees
      2. Moror B: make the needed calculations to move forward z cm
      3. Predict what the outcome would be
      4. Give the ‘GO’ to all actions! (send via multithreading to all motors)
      5. Check the outcome (via sensons) with our prediction
      6. Goto step 1 to make adjustments towards our target

      You may have a look into what the hardware of Lego’s MINDSTORMS NXT is capable of.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: