Home / Programming / ROBOTC / ROBOTC on EV3: Getting Closer!

ROBOTC on EV3: Getting Closer!

There has been an enormous amount of progress in the past few weeks on the ROBOTC for EV3.  Many bugs and issues were fixed in the base LEGO VM that were causing issues, such as failed auto-id and I2C transactions.

Pretty soon I can start working on porting the Driver Suite to the EV3.  Some things like I2C will be different but so badly that it will take a lot of work to get it up and running.  However, I did mention in a previous post that I am also working on a massive rewrite of the suite to make it more struct-oriented.  This is still on the agenda.

So the status right now is that there’s basic motor and sensor control, so it’s actually possible to make functional robots.  The debugging windows and all that fun stuff is also working.  You can watch variables, sensors and motors.

Below is a video Tim Friez made of his robot not running into a wall.

I fiddled a bit more with it and made a (slow) line following robot:

Below you can find the source code of these programs.  As you can see, it’s not a lot different from what you’re used to with the NXT or VEX IQ or any other ROBOTC platform.

The don’t-bump-into-the-wall robot:

#pragma config(Sensor, S4, sonar4, sensorEV3_Ultrasonic)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
  sleep(1000);

  while(SensorValue[sonar4] > 6)
  {
    motor[motorB] = -50;
    motor[motorC] = -50;
  }

  motor[motorB] = 0;
  motor[motorC] = 0;
  sleep(3000);
}

This is the linefollower:

#pragma config(Sensor, S3,     colour,         sensorEV3_Color) 
#pragma config(Motor,  motorB,          leftwheel,     tmotorEV3_Large, PIDControl, reversed, encoder) 
#pragma config(Motor,  motorC,          rightwheel,    tmotorEV3_Large, PIDControl, reversed, encoder) 
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*// 
int nMotorSpeedSetting = 30; 
float nPfactor = 0.3; 
int grey = 50; 
int lowest = 100; 
int highest = 0; 
void scanLine() 
{ 
  motor[leftwheel] = 10; 
  motor[rightwheel] = -10; 
  time1[T1] = 0; 
  while(time1[T1] < 500) 
  { 
    if (SensorValue[colour] > highest) 
    { 
      highest = SensorValue[colour]; 
    } 
    if (SensorValue[colour] < lowest) 
    { 
      lowest = SensorValue[colour]; 
    } 
  } 
  grey = (highest - lowest) / 2; 
  motor[leftwheel] = 0; 
  motor[rightwheel] = 0; 
} 

task main() 
{ 
  float error; 
  scanLine(); 
  while (true) 
  { 
    error = SensorValue[colour] - grey; 
    motor[leftwheel] = nMotorSpeedSetting - round(error * nPfactor); 
    motor[rightwheel] = nMotorSpeedSetting + round(error * nPfactor); 
    wait1Msec(50); 
  } 
}

Make sure you keep your eyes peeled as a public beta program will start very soon, once things like LCD and LED control have been added.  You can also follow a thread on the ROBOTC forums where the devs post what’s going on.  If you are keen to take part in the beta trials, make sure you buy yourself a 4GB SD card (or bigger), so you can run the special firmware.  I bought these class 10 cards very cheaply from DX.com.  I’ve really hammered them over the past few months and they’re holding up very nicely.

Stay tuned!

About Xander

Xander Soldaat is a Software Engineer and former Infrastructure Architect. He loves building and programming robots. He recently had the opportunity to turn his robotics hobby into his profession and has started working for Robomatter, the makers of ROBOTC and Robot Virtual Words.