Write Your First Robotics Software

Techhub | 2:04 AM | 0 comments

first robo code

This tutorial continues from the last part Let's make a first robot using VEX

As much as the hardware of your robot, Software design is also a very important part. You learned how to make a robot from the last part of this tutorial, from this one you'll be learning how to write your first Robotic software. 
Software is the soul of your robot it enables your robot to think and perform different tasks you assign. Present robotics codes are developed in C, C++, Java, Octave and some other programming platforms. For this project we'll be using C language, C being a low level language its certainly close to Machine language, That make the C language a very suitable language to program robots.


your first robotic program
You can use different kinds of development studios to program your robot but I'd prefer if you use ROBOTC its a very powerful studio tuned to tweak the performances of your robot.  It has a build in Simulator world where you can test your robot in different situations and virtual worlds, and you can upload  your program directly right off the editor to your robot. Its a paid software but you will have all the features in 30-day Trial.



Installing ROBOTC

System Requirments to run ROBOTC on your computer

System Requirements:
Intel® Pentium® processor or compatible, 800 MHz minimum 
Windows XP Professional or Home Edition with Service Pack 2 or greater 
256MB of RAM minimum 
Up to 30MB of available hard disk space 
1 available USB port 
Compatible Bluetooth adapter (optional)

ROBOTC Virtual Worlds System Requirements:
Intel® Core 2 Duo®/AMD® Athlon X2® or better processor 
Windows XP Home or Professional Edition with Service Pack 2 or greater, Windows Vista, Windows 7 
2048 MB (2 GB) of RAM minimum 
Minimum 200MB free hard drive space 
NVIDIA® GeForce® 8800GTS/ATI Radeon™ HD 3850 or better video card 
DirectX® 9.0 or DirectX® 10 



Downloading ROBOTC

Before we start programming in ROBOTC, we need to first download and install the client. This can be done by [Clicking here] additionally you can look up ROBOTC's website (https://www.robotc.net) and selecting the 'Downloads' tab.


Installing ROBOTC

1) Once the program is done downloading, navigate to the Downloads folder on your computer and start the ROBOTC installer. You may have to right click on the installer and select the "Run as Administrator" depending on individual computer restrictions; ROBOTC must be installed with administrator privileges.

2) Before you can proceed, you must read over and accept the End User License Agreement. If you agree to the End User Agreement, check the "I accept" and then the "Next" button to continue the installation.

3) Next, select where you would like ROBOTC to install to. The default location is C:/Program Files (x86)/Robomatter Inc/ROBOTC Development Environment.

4) The installer will ask you to confirm your settings. If everything looks correct, click "Install" to being the installation process. The installer will then begin copying files from the installer to your computer. Please wait until this is complete.

5) The installer will inform you of when the installation is complete. Click the "Finish" button to complete your install.

6) Right-Click on the ROBOTC icon and select "Run as Administrator" to run ROBOTC as an administrator (assuming the user account has administrator privileges). You will only need to do this one time.

Building Licenses

There is a special type of ROBOTC license called a Building License . These licenses do not require an online activation but rather have a unique building license file that must be installed with the software in order for ROBOTC to work properly. When you order a building license you will be sent an email with a unique building license file.

To activate ROBOTC with a building license, download and run the installer as normal. Once the program is installed, copy the building license file into the ROBOTC directory (typically C:/Program Files (x86)/Robomatter Inc/ROBOTC Developement Environment).

One of the advantages of building licenses is that they help make automated installs easy. To roll out ROBOTC to multiple computers using a building license, make sure the base image has ROBOTC installed and the building license files in the correct directory. As long as those two conditions are met, ROBOTC should be active on each computer the image is rolled out to with no futher action required.

There is, however, an exception. If ROBOTC is being run from a centralized network, each computer that needs to access ROBOTC must also install a Network Dependencies package (available from the ROBOTC downloads page). The building license file must also be properly installed on the network in order for networked computers to access ROBOTC.

Activating ROBOTC

To continue using ROBOTC past the 30 day trial period, you must purchase a ROBOTC license and then activate the license on each computer.

To activate ROBOTC, you will need the License ID and Password that was sent to you during the purchase process.
  • If you purchased a ROBOTC license online, the License ID and Password were sent to the email address specified.
  • If you ordered the CD-ROM version of ROBOTC, the License ID and Password are printed on the CD label.

If you are Activating the ROBOTC license on computers with internet access, follow the Activation instructions below.
NOTE: ROBOTC must be activated on each individual computer. ROBOTC can no longer be activated offline; the computers must be activated with a working internet connection. Once activation is complete, the computers do not need to remain online to stay activated.

Follow these steps to activate on a computer with internet access:
1) Open ROBOTC and navigate to the Help menu. From there, select 'Manage Licenses -> Add License'. If you do not already have a ROBOTC license, you may purchase one by clicking the 'Purchase License' option.


Source:  http://www.education.rec.ri.cmu.edu


Driver Installation 


You will need :

  1. A ROBOTC for IFI Installation CD or Internet connection
  2. A VEX USB-to-Serial cable

Plug in the A VEX USB-to-Serial cable USB end to the ComputerCancel any automatic installation prompts that may appear, such as the “Found New Hardware Wizard” Window. Instead, run the driver installation program manually from the ROBOTC for IFI CD-ROM or download and run the driver from the ROBOTC.net website. For downloading instructions, see step 3.


If you dont have the CD you may have to download the driver from ROBOTC Prolofic USB-to-Serial Driver, the installation file will need to be extracted before you can start the installation process. Extract the “prolific_usb_driver” file by right-clicking its icon, selecting “Extract All...”, and proceeding through the following steps. Once complete, run the “SETUP” file and follow the its instructions to finish installing the USB-to-Serial driver. 
Re-plug the Cable 


Firmware installation 

Plug the Robot Interface (“telephone”) Cable and the USB-to-Serial cable into the Programming Module.


Plug the free USB connector end of the Programming cable into a USB port on your computer.  

Plug the other unconnected end of the cable into the “SERIAL” port of your VEX Micro Controller.
If the VEX Micro Controller is not already turned on, turn it on now.  

Run RobotC



First Screen

Your main window should look like this 





Now that ROBOTC is open, go to the View menu and select Preferences. A new window with a Platform tab appears. Select the platform type and COM port for your robot.

From the Robot menu, select Download Firmware.

The Select VEX firmware file window appears. The VEX firmware file starts with “VEX” and has a number. If more than one file starts with “VEX”, choose the one with the highest number. Choose Open to start downloading the VEX firmware.



Restart your VEX Micro Controller to complete the download firmware process.


Your robot is now ready to be used with ROBOTC 



Programming 

After you successfully connect the your robot, start writing your first robocode. RobotC programming interface and methods are easy to understand even for a very beginner. Thats another reason to use RobotC in this project. 

 Before you begin programming your Arduino in ROBOTC, you'll need to let ROBOTC know which Arduino board you are using. To do this, go to the Robot menu and select Platform Type → Arduino → Standard Arduino and choose your board from one of the choices.


Select your Serial Port


Once your Arduino's Type is selected, you'll need to select which serial port the Arduino is connected to on your computer. Go to the View menu and choose Select Communication Port. From here, you'll pick your Arduino board from the dropdown menu.

Starting a New Code

To start writing your code go File - New - New File 

This is the sample code of a Line Following Robot, Please refer to the comments to understand what each part of this code does.



#pragma config(Sensor, dgtl1,  rightEncoder,        sensorQuadEncoder)
#pragma config(Sensor, dgtl3,  leftEncoder,         sensorQuadEncoder)
#pragma config(Sensor, dgtl5,  compassSensor,       sensorVirtualCompass)
#pragma config(Sensor, dgtl6,  touchSensor,         sensorTouch)
#pragma config(Sensor, dgtl8,  sonarSensor,         sensorSONAR_inch)
#pragma config(Motor,  port2,           rightMotor,    tmotorNormal, openLoop)
#pragma config(Motor,  port3,           leftMotor,     tmotorNormal, openLoop,reversed)
#pragma config(Motor,  port6,           gripper,       tmotorNormal, openLoop)
#pragma config(Sensor, in1,    lineTrackerLeft,     sensorLineFollower)
#pragma config(Sensor, in2,    lineTrackerCenter,   sensorLineFollower)
#pragma config(Sensor, in3,    lineTrackerRight,    sensorLineFollower)




task main()
{
wait1Msec(2000);// waiting time before the program execute

 int threshold;
 threshold = 1500;// initiate a threshold 

 while(1 == 1)//while the value is equal to 1 do the last within brackets
 {
  if(SensorValue(lineTrackerLeft) > threshold) // if the left sensor goes dark above the threshold deactivate the left motor and keep the right motor
  {
     motor[leftMotor] = 0;
     motor[rightMotor] = 100;

 }
 { if(SensorValue(lineTrackerCenter) > threshold) // center sensor goes dark above the threshold keep both motors running

      motor[leftMotor] = 100;
      motor[rightMotor] = 100;
 }

{ if(SensorValue(lineTrackerRight) > threshold)// if the right sensor goes dark above the threshold deactivate the right motor and keep the left motor


    motor[leftMotor] = 100;
    motor[rightMotor] = 0;

}
  }

}

Once your program is completed, you can download it to your Arduino controller by going to the Robot menu and selecting Compile and Download or by simply pressing F5.


The ROBOTC debug windows appear when the download is complete. Sometimes only the Program Debug window will appear. This is not a problem, simply a setting in ROBOTC.


Also ROBOTC has a number of sample programs  for you to learn how to program and use your Arduino board. You can open a sample program by going to the File menu and selecting Open Sample Program. Once you're in the open sample programs directory, make sure you choose your Correct Sample Program Folder for your Arduino.

Voila!! you wrote your first robocode. Make sure you try different codes as your imagination to improve your coding.

Category: ,

About Ranusha De Silva:
Ranusha is a blogger/enthusiastic person. Apart from blogging, passionate in Technology, Aviation,Robotics, Traveling and the Joy of living. IOS Lover, Windows 7,8 , Snow Leopard and Redhat user, Dreamer with an unfinished novel since 6 years old yet still ambitious. Please contact me via my email or grab my Feedburner to stay updated.

0 comments

Back to Top