Monday, September 24, 2012

RobotC Software Training

TBD members Jaret and Tyler recently attended a RobotC training program at Rockwell Automation. Most of the work was review, but we did learn to fix a compiler issue and work the infrared sensor. Code samples are below:

Using the Joystick

#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     QuickMotor,    tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNone, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#define ROBOTC_JOYBTN_LB 5
#define ROBOTC_JOYBTN_RB 6

#include "JoystickDriver.c"

task main()
{

 while(true)
 {
  getJoystickSettings(joystick);

  if(joy1Btn(ROBOTC_JOYBTN_LB))
  {

   ClearTimer(T1);

   while(time1[T1] <= 5000 && joy1Btn(ROBOTC_JOYBTN_RB) == false)
   {
    motor[QuickMotor] = 100;
   }

   motor[QuickMotor] = 0;

  }

 }

}

Using Motors

#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     EpicMotor,     tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNone, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{

 nMotorEncoder[EpicMotor] = 0;
 while(nMotorEncoder[EpicMotor] < 360)
 {
  motor[EpicMotor] = 100;
 }

 motor[EpicMotor] = 0;

}

Using Sensors

#pragma config(Sensor, S1,     Sensor,         sensorI2CHiTechnicAccel)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{

 while(true)
 {

  nxtDisplayTextLine(0, "Value: %d", SensorValue[Sensor]);
    nxtDisplayTextLine(1, "Value: %d", (SensorValue[Sensor] / 2));
    nxtDisplayTextLine(2, "Value: %d", (SensorValue[Sensor] / 4));
    nxtDisplayTextLine(3, "Value: %d", (SensorValue[Sensor] / 8));
    nxtDisplayTextLine(4, "Value: %d", (SensorValue[Sensor] / 16));
    nxtDisplayTextLine(5, "Value: %d", (SensorValue[Sensor] / 32));
  nxtDisplayTextLine(6, "Value: %d", (SensorValue[Sensor] / 64));
    nxtDisplayTextLine(7, "Value: %d", (SensorValue[Sensor] / 128));

 }

}

Using the Timers

task main()
{

 ClearTimer(T1);
 nxtDisplayTextLine(1, "Waiting...");

  while(nNxtButtonPressed != 3)
  {
   nxtDisplayTextLine(1, "Elapsed: %d", time1[T1]);
  }

  eraseDisplay();
  nxtDisplayTextLine(1, "Elapsed: %d", time1[T1]);
  wait1Msec(2000);

}



No comments:

Post a Comment