In the previous post I talked about the algorithm and general information regarding remembering a path and tracing it.

Here you will have a look at the actual code. But first, lets build a flow chart covering the classes included in the program:

  • The form itself: FormRobot [Design]
  • The form programmer: FormRobot.cs
  • ClsRobotUtilities
  • RobotHandler
  • Interface
That is the form and the window that pops-up when debugging the program.
It shows the status of the robot as well as real time motion simulation, in addition to all the buttons which are used to control the robot.

Flow chart describing class configuration:chart  in FormRobot: Functions: are various methods for tracing straight and reverse and calling up the right rout, basically, this is the core of the project which will be emphasized later on.

  • ClsRobotUtilities :


  • RobotHandler:1

Notice that in this class there is the main List<> “mapList” that we record the first path in it, which we will refer to later as the “Original Path” because all the paths splits off it.

  • FormRobot.cs:

this part of the code, as I declared previously, is the core of the project. it contains the functions that read the keyboard buttons when pressed, as well as saving the data and extracting it when needed. Before we go further, you should know how the program works: First, press the button “Record”on the form, then start controlling the robot via the keyboard, then, when finishing the route, press again the same button, which now reads “Stop”. In this process we actually taught the robot a route that it now capable of tracing straight and backward-reverse, to make it do so, simply press the buttons that reads accordingly.                                                                                                                                      The most important variable in this class is a variable of the type RoborHandler which is called “robot”, we need this variable so we will have access to the mapList, and we do so by writing: “robot.mapList;”.

Button: Record-Stop: when clicking that button:

  1. first, the reading of the button changes: if it was reading Record, it now starts to read Stop, and vice versa.
  2. adding the first object to the list(data structure) which is a ‘Stop’ node, because of the elapsed time between clicking and moving to the keyboard buttons.
  3. Activating the timer(Steps_Timer) that moves the robot and measure the time we clicked on each button.

Play Button: similar to the previous button, this one does the reversed function of the first:

  1. Selects the starting ‘Index’ as zero, since we want to trace from the beginning of the path.
  2. Activates a timer(Timer_Play) that goes over each object of the list and interpret the meaning of the direction and time(interval) to a robot motion, thus the path we saved earlier is preserved and the robot has the ability to trace it again.

Add Path Button: this is the most important of all:

  1. Stops the robot’s motion.
  2. Saves the Robot current position on the Original-Path in an ‘int’ variable, this variable contains the index of the object that we stopped the robot in.
  3. Here we build another List<>(int) to classify the splitting, and we call it: “subPathSerialIndex”. In this list we save the index of which we split to the sub path. which means that serial index of this list(which starts from zero by default) is the same serial position of the sub-path which indicates the object is split from in respect to the Original Path:
    the upper line entitles the List<> index, which starts from zero by default(like in arrays). The List's objects contains a number which indicates the index in the mapList(which is located in RobotHandler class) that the subPath has split from.
    the upper line entitles the List<> index, which starts from zero by default(like in arrays). The List’s objects contains a number which indicates the index in the mapList(which contains the Original Path) that the subPath has split from.

    *As you have noticed, the subPath serial number is greater by 1 than the List index number, there for when we want to declare the subPath serial number from that List we go to the “index+1”.

  4. Sometimes we stop in the middle of the node:                                                                         if the node we stopped in was”Forward, 100[msec]”, and we stopped in 40[msec], then we need to divide the node that contains “Forward, 100[msec]” into 2 nodes: one is “Forward, 40[msec]” and the second is “Forward, 60[msec]”. The code below describe this process: 

    the variable tmpInterval holds the time elapsed in the node before we decided to split
    the variable tmpInterval holds the time elapsed in the node before we decided to split. SubMapList is another List<> identical to mapList in type that we save the subPath in it.

That is basically how the program thinks, in the next post i will refer to the hardware and schematics of the wiring, as well as the interface itself(usb 1208ls), which is not very popular with robots.

due to the large code and my inexperience with WordPress, i cant post the entire code here. please post a comment if you need further explanation, or use the contact form.