ROBOTC.net forums
http://www.robotc.net/forums/

Concurrent tasks
http://www.robotc.net/forums/viewtopic.php?f=52&t=4289
Page 1 of 1

Author:  mingdooley [ Sat Feb 25, 2012 4:34 am ]
Post subject:  Concurrent tasks

How do we insert code to move servos 1 and 12 to a different position at the same time as the rest of this code runs?

Code:
#pragma config(Hubs,  S1, HTServo,  HTServo,  HTMotor,  HTMotor)
#pragma config(Sensor, S1,     ,                    sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C3_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     motorE,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C4_1,     motorF,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C4_2,     motorG,        tmotorNormal, openLoop)
#pragma config(Servo,  srvo_S1_C1_1,    servo1,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_2,    servo2,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_3,    servo3,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_4,    servo4,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_5,    servo5,               tServoStandard)
#pragma config(Servo,  srvo_S1_C1_6,    servo6,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_1,    servo7,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_2,    servo8,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_3,    servo9,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_4,    servo10,              tServoStandard)
#pragma config(Servo,  srvo_S1_C2_5,    servo11,              tServoStandard)
#pragma config(Servo,  srvo_S1_C2_6,    servo12,              tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.

void initializeRobot()
{
  //from the front of the robot
  servo[servo1] = 138; //right bowling ball servo up pos
  servo[servo12] = 96; //left bowling ball servo up pos

  servo[servo7] = 0; //from the front, the left hand servo is a 0 when the arm is extended. It is at 229 when it is at its lowest.
  servo[servo8] = 0; //from the front, the right hand servo is a 26 when the arm is extended. It is at 255 when it is at its lowest.

  servo[servo9] = 225; //small servo joint
  servo[servo2] = 0;

  servo[servo11] = 225;
  return;
}

task main()
{
  nNoMessageCounterLimit = 200;
  initializeRobot();

  waitForStart(); // Wait for the beginning of autonomous phase.

 //Going forwards

  motor[motorD] = 40;
  motor[motorE] = -40;
  wait1Msec(2000);

  motor[motorD] = 0;
  motor[motorE] = 0;
  wait1Msec(500);

  //Going back

  motor[motorD] = -40;
  motor[motorE] = 40;
  wait1Msec(250);

  motor[motorD] = 0;
  motor[motorE] = 0;
  wait1Msec(500);

  //Turning

  motor[motorD] = 50;
  motor[motorE] = 50;
  wait1Msec(800);

  motor[motorD] = 0;
  motor[motorE] = 0;
  wait1Msec(500);

  //Going forward after turning

  motor[motorD] = -40;
  motor[motorE] = 40;
  wait1Msec(5000);

  motor[motorD] = 0;
  motor[motorE] = 0;
  wait1Msec(500);


  while (true)
  {}

}

Thanks,
Ming

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/