Ejemplo n.º 1
0
bool isBeaconInRange(tSensors irSensor)	// subroutine that determines whether IR beacon is in range
{
	wait1Msec(1);
	int ir = SensorValue[irSensor];	// defines integer that returns current sensor value
	nxtDisplayCenteredTextLine(2, "ir = %d", ir);
	wait1Msec(1);
	if (ir == 0)	// no beacon detected
	{
		return false;
	}
	else	// beacon detected
	{
		return true;
	}
}
task main() {
  byte inputs = 0;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "Proto");
  nxtDisplayCenteredTextLine(3, "Test 1");
  nxtDisplayCenteredTextLine(5, "Connect SMUX to");
  nxtDisplayCenteredTextLine(6, "S1 and HTPB to");
  nxtDisplayCenteredTextLine(7, "SMUX Port 1");
  wait1Msec(2000);

  PlaySound(soundBeepBeep);
  while(bSoundActive) EndTimeSlice();

  eraseDisplay();

  while(true) {
    // Fetch the state of the digital IO pins.  When not explicitly
    // configured as input or output, they will default to input.
    inputs = HTPBreadIO(HTPB, 0x3F);
    nxtDisplayTextLine(4, "D: 0x%x", (int)inputs);
    wait1Msec(10);
  }
}
void hashtagyoloswagdiem(){
	nxtDisplayCenteredTextLine(1, "KICKING");
	wait10Msec(300);
	motor[Dribbler] = 0;
	if(SensorValue(TouchSensor) == 1){
		while(SensorValue(TouchSensor) == 1){    // While the Touch Sensor is inactive (hasn't been pressed):
	  	motor[Kicker] = 100;
	  }
	}
  while(SensorValue(TouchSensor) == 0){		// While the Touch Sensor is active (has been pressed):
  	motor[Kicker] = 100;
  }
  motor[Kicker] = 0;
  motor[Dribbler] = 100;
}
Ejemplo n.º 4
0
void corridorTurn(int currentWaypoint, int destinationWaypoint)
{
  //Turn based on arguments.
  //Face sonar to the correct wall.

  nxtDisplayCenteredTextLine(4, "from: %d", currentWaypoint);
  nxtDisplayCenteredTextLine(5, "to: %d", destinationWaypoint);
  //wait1Msec(1000);

  float a = 0;
  switch(currentWaypoint)
  {
    case 1:
      a = PI/2;
      break;
    case 2:
      a = (destinationWaypoint == 1) ? -PI/2 : PI/2;
      break;
    case 3:
      a = -PI/2;
      break;
  }
  turnRadiansClockwise(a);
}
Ejemplo n.º 5
0
void turnPointLeft (float mRot, float mRotPerSec)
{
	nxtDisplayCenteredTextLine(5, "TPL(%.2f,%.2f)",
		mRot, mRotPerSec);

	if (moveModeType != MMAllMoveTypes
	      && moveModeType != MMTurnsOnly
	      && moveModeType != MMPointTurnsOnly) {
		return;
	}

	if (moveModeTiming == MMOneMoveAtATime) {
		waitForTouch();
	}


	if (stepThroughMode == stepThroughModeOn) {
		waitForTouch();
	}

	checkParameterRange(mRot, mRotPerSec);

	int leftWheelInitial = nMotorEncoder[leftWheelMotor];
	int rightWheelInitial = nMotorEncoder[rightWheelMotor];
	int leftWheelTarget = nMotorEncoder[leftWheelMotor] - 360 * mRot;
	int rightWheelTarget = nMotorEncoder[rightWheelMotor] + 360 * mRot;

	ClearTimer(T1);

	float motorPower = revolutionsPerSecondToMotorPower(mRotPerSec);
	motor[leftWheelMotor] = -1 * motorPower;
	motor[rightWheelMotor] = motorPower;

	while ((nMotorEncoder[leftWheelMotor] > leftWheelTarget)
		&& (nMotorEncoder[rightWheelMotor] < rightWheelTarget))
	{
		nxtDisplayCenteredTextLine(7, "%d", nMotorEncoder[leftWheelMotor]);
	}

	motor[leftWheelMotor] = 0;
	motor[rightWheelMotor] = 0;

	int leftWheelChange = nMotorEncoder[leftWheelMotor] - leftWheelInitial;
	int rightWheelChange = nMotorEncoder[rightWheelMotor] - rightWheelInitial;
	float revolutionsWheelsRotated =
	  ((float) ( abs(leftWheelChange) > abs(rightWheelChange) ?
	                leftWheelChange : rightWheelChange ))
	        / 360.0;

	nxtDisplayCenteredTextLine(2, "TPL(%.2f,%.2f)",
		mRot, mRotPerSec);
	nxtDisplayCenteredTextLine(3, "%.2frev %.2fsec",
	  (float) revolutionsWheelsRotated, (float) time10(T1) / 100);
	nxtDisplayCenteredTextLine(5, "");
	nxtDisplayCenteredTextLine(7, "");
}
void turnRightTillLine(){
	move=true;
	while(move)
			{
				motor[motorD] = 30;
				motor[motorE] = 0;
				sColor = SensorValue[colorport];
				if (sColor > colorMid) move = false;
			  StringFormat(disp,"%d", sColor);
			  nxtDisplayCenteredTextLine(2, disp );
			  }
				// move in opposite direction to be back on the line
				motor[motorD] = 0;
				motor[motorE] = 0;
				wait10Msec(100);
}
void initializeRobot()
{

	eraseDisplay();
	string print;
	int n = 0;
	while (n<400){
	print = SensorValue[IRSeeker];
	nxtDisplayCenteredTextLine(0,print);
	wait10Msec(10);
	n = n + 1;
	}

	return;

}
Ejemplo n.º 8
0
//x and y in meters
void navigateToWaypoint (float new_x, float new_y)
{
	new_x *= 100;
	new_y *= 100;
	float dx = new_x - x;
	float dy = new_y - y;
	nxtDisplayCenteredTextLine(1, "x: %f", dx);
	nxtDisplayCenteredTextLine(2, "y: %f", dy);
	float targetAngle = 0;
	if (dy != 0)
	{
		targetAngle = atan( dx / dy );
	} else {
		targetAngle = PI/2;

	}
	nxtDisplayCenteredTextLine(4, "TA: %f", targetAngle);
	//SW quadrant
	nxtDisplayCenteredTextLine(5, "HERE: %f", (float)0);
	if(dy < 0 && dx >= 0)
	{
		targetAngle += PI;
		nxtDisplayCenteredTextLine(5, "HERE: %f", (float)1);
	}
	//NW
	if (dy <= 0 && dx < 0)
	{
		targetAngle -= PI;
		nxtDisplayCenteredTextLine(5, "HERE: %f", (float)2);
	}
	if(dy > 0 && dx < 0)
	{
		targetAngle = -atan( abs(dx) / dy );
		nxtDisplayCenteredTextLine(5, "HERE: %f", (float)3);
	}

	float newAngle = targetAngle - theta;
	nxtDisplayCenteredTextLine(3, "NA: %f", newAngle);

	wait1Msec(1000);
	turnNDegrees(newAngle);

	moveForward(sqrt((dx*dx) + (dy*dy)));
}
/**
 * Turns around until black is found
 */
void turnToLine(void) {
  spinInDirection();

	while(!isDark()) {
		abortTimeslice();
	}
	int startDir = currentDirection();

	while(isDark()) {
	  abortTimeslice();
  }
	motor[left] = 0;
	motor[right] = 0;
	int centre = startDir + (angleDifference(currentDirection(), startDir)/2);
	nxtDisplayCenteredTextLine(6, "cen: %i", centre);
	turnToAngle(centre, 0);
}
task main () {
  int _color = 0;
  string _tmp;
  int red = 0;
  int green = 0;
  int blue = 0;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "COLOUR");
  nxtDisplayCenteredTextLine(3, "SMUX Test");
  nxtDisplayCenteredTextLine(5, "Connect SMUX to");
  nxtDisplayCenteredTextLine(6, "S1 and CS to");
  nxtDisplayCenteredTextLine(7, "SMUX Port 1");
  wait1Msec(2000);

  eraseDisplay();
  while (true) {

    // Read the currently detected colour from the sensor
    _color = HTCSreadColor(HTCOLOR);

    // If colour == -1, it implies an error has occurred
    if (_color < 0) {
      nxtDisplayTextLine(4, "ERROR!!");
      nxtDisplayTextLine(5, "HTCSreadColor");
      wait1Msec(2000);
      StopAllTasks();
    }

    // Read the RGB values of the currently colour from the sensor
    // A return value of false implies an error has occurred
    if (!HTCSreadRGB(HTCOLOR, red, green, blue)) {
      nxtDisplayTextLine(4, "ERROR!!");
      nxtDisplayTextLine(5, "HTCSreadRGB");
      wait1Msec(2000);
      StopAllTasks();
    }

    // Read the RGB values of the currently colour from the sensor
    // A return value of false implies an error has occurred
    nxtDisplayCenteredTextLine(0, "Color: %d", _color);
    nxtDisplayCenteredBigTextLine(1, "R  G  B");

    nxtEraseRect(0,10, 99, 41);
    nxtFillRect( 0, 10, 30, 10 + (red+1)/8);
    nxtFillRect(35, 10, 65, 10 + (green+1)/8);
    nxtFillRect(70, 10, 99, 10 + (blue+1)/8);
    StringFormat(_tmp, " %3d   %3d", red, green);
    nxtDisplayTextLine(7, "%s   %3d", _tmp, blue);

    wait1Msec(100);
  }
}
Ejemplo n.º 11
0
////////////////////////////////////////////////////////////////////////////////
//Select Robot Start Location (Wall) -----------------------------------------//
////////////////////////////////////////////////////////////////////////////////
void selectStartLocation()
{
	eraseDisplay();
	// Enable Top Line NXT Display (Bluetooth, NXT Name & Battery Status)
	//bNxtLCDStatusDisplay = true;
	while(true)
	{
		nxtDisplayCenteredTextLine(1,"DITU SAYS WEAR");
		nxtDisplayCenteredTextLine(2,"SAFETY GLASSES");
		nxtDisplayCenteredTextLine(4,"Start Location:");
		//------------------------------------------------
		if(nNxtButtonPressed == 1)	// NXT Right Triangle Button
		{
			robotStartLocation++;
			wait1Msec(400);
		}
		//-------------------------------------------------
		if(nNxtButtonPressed == 2)	// NXT Left Triangle Button
		{
			robotStartLocation--;
			wait1Msec(400);
		}
		// Keep AutoActions within a range of valid values
		if (robotStartLocation > 2) robotStartLocation = 2;
		if (robotStartLocation < 0) robotStartLocation = 0;
		//-------------------------------------------------
		switch (robotStartLocation)
		{
		case 0: nxtDisplayCenteredTextLine(6, "Left Wall");break;
		case 1: nxtDisplayCenteredTextLine(6, "Corner");break;
		case 2: nxtDisplayCenteredTextLine(6, "Right Wall");break;
		case 3: nxtDisplayCenteredTextLine(6, "Under Rack");break;
		default: nxtDisplayCenteredTextLine(6, "Error");break;
		}
		//---------------------------------------------------------------
		if(nNxtButtonPressed == 3)	// NXT Orange Button
		{
			wait1Msec(400);
			break;
		}
		//---------------------------------------------------------------
	}
}
Ejemplo n.º 12
0
task main()
{
  init();

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

  ///////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////
  ////                                                   ////
  ////    Add your robot specific autonomous code here.  ////
  ////                                                   ////
  ///////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////

  while((fs1<25&&fs1>1000||fs1<1400)||(fs2<1400||fs2<25&&fs2>1000)){
		fs1 = HTFreadSensor(HTFS1);
		fs2 = HTFreadSensor(HTFS2);
		HTIRS2readAllDCStrength(HTIRS2,dcS1,dcS2,dcS3,dcS4,dcS5);
		nxtDisplayCenteredTextLine(1,"IRSensor\n%i\n%i\n%i\n%i\n%i)",dcS1,dcS2,dcS3,dcS4,dcS5);
		if(dcS1>5||dcS2>5||dcS3>5||dcS4>5||dcS5>5){
			if(dcS3>dcS1&&dcS3>dcS2&&dcS3>dcS4&&dcS3>dcS5){
				forward(power);
			}
			else if(dcS1+dcS2>dcS4+dcS5){
				rotateLeft(power);
			}
			else if(dcS1+dcS2<dcS4+dcS5){
				rotateRight(power);
			}
			else{
				stop();
			}
		}
		else{
			forward(power/2);
		}
	}
	servoPos=255;
	stop();
	wait1Msec(1000);
	servo[servo1]=servoPos;
	reverse(power);
	wait1Msec(500);
	stop();
}
Ejemplo n.º 13
0
task main()
{
string sColor;

while (true) {
switch (SensorValue[S4])
{
case 0: sColor = "Black"; break;
case 2: sColor = "Blue"; break;
case 4: sColor = "Green"; break;
case 6: sColor = "Yellow"; break;
case 8: sColor = "Red"; break;
case 17: sColor = "White"; break;
default: sColor = "???"; break;
}
nxtDisplayCenteredTextLine(2, sColor);
wait1Msec(50);
}
}
task main()
{
	string sColor;
	while(true)
	{
    switch (SensorValue[colorSensor])
    {
      case BLACKCOLOR: sColor = "Black"; break;
      case BLUECOLOR: sColor = "Blue"; break;
      case GREENCOLOR: sColor = "Green"; break;
      case YELLOWCOLOR: sColor = "Yellow"; break;
      case REDCOLOR: sColor = "Red"; break;
      case WHITECOLOR: sColor = "White"; break;
      default: sColor = "???"; break;
    }
    nxtDisplayCenteredTextLine(2, sColor);
    wait1Msec(50);
	}
}
Ejemplo n.º 15
0
task main()
{
initializeRobot();
waitForStart();


	while(nMotorEncoder[RightDrive] < 4*360*0.4)
	{
		moveForward(70);
	}
	// STEP 2: Deploy auto-scoring arm
	servoTarget[autoServo] = 200;
	wait1Msec(500);
	servoTarget[autoServo] = 255;
	wait1Msec(500);

	while(nMotorEncoder[RightDrive] < 4*360*0.8)
	{
		moveForward(70);
	}

	motor[LeftDrive] = 70;
	motor[RightDrive] = -70;
	while(true)
	{
		nxtDisplayCenteredTextLine(3, "Heading: %d", currHeading);
		wait1Msec(10);
		if (currHeading >= 90 && currHeading < 110) break;
	}
	halt();
	resetEncoders();
	wait1Msec(100);

		//STEP 7: Drive onto ramp
	while(nMotorEncoder[RightDrive] > -(4*360*3))
	{
		moveForward(-70);
	}
	halt();
	currHeading = 0.0;
	wait1Msec(100);

}
Ejemplo n.º 16
0
////////////////////////////////////////////////////////////////////////////////
//Select Program--------------------------------------------------------------//
////////////////////////////////////////////////////////////////////////////////
void selectProgram()
{
  eraseDisplay();
  // Enable Top Line NXT Display (Bluetooth, NXT Name & Battery Status)
  bNxtLCDStatusDisplay = true;
  while(true)
  {
    nxtDisplayCenteredTextLine(1,"DITU SAYS WEAR");
    nxtDisplayCenteredTextLine(2,"SAFETY GLASSES");
    nxtDisplayCenteredTextLine(4, "Select Test:");
    //------------------------------------------------
    if(nNxtButtonPressed == 1)
    {
      Program++;
      wait1Msec(400);
    }
    //-------------------------------------------------
    if(nNxtButtonPressed == 2)
    {
      Program--;
      wait1Msec(400);
    }
    //-------------------------------------------------
    switch (Program)
    {
    case 0: nxtDisplayCenteredTextLine(6, "No Auto");break;
    case 1: nxtDisplayCenteredTextLine(6, "One Auto Ring");break;
    case 2: nxtDisplayCenteredTextLine(6, "Two Auto Rings");break;
    case 3: nxtDisplayCenteredTextLine(6, "One Auto W/ Normal Rings");break;
    case 4: nxtDisplayCenteredTextLine(6, "Two Auto W/ Normal Rings");break;
    }
    //---------------------------------------------------------------
    if(nNxtButtonPressed == 3)
    {
      eraseDisplay();
      break;
    }
    //---------------------------------------------------------------
  }
}
Ejemplo n.º 17
0
task main () {
  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "MAGNETIC");
  nxtDisplayCenteredTextLine(3, "Field Sensor");
  nxtDisplayCenteredTextLine(4, "Test 1");
  nxtDisplayCenteredTextLine(5, "Connect Sensor");
  nxtDisplayCenteredTextLine(6, "to S1");

  wait1Msec(2000);

  nxtDisplayCenteredTextLine(5, "Press enter");
  nxtDisplayCenteredTextLine(6, "to set bias");

  wait1Msec(2000);
  eraseDisplay();
  while(true) {
    eraseDisplay();
    nxtDisplayTextLine(1, "Resetting");
    nxtDisplayTextLine(2, "bias");
    wait1Msec(500);

    // Start the calibration and display the offset
    nxtDisplayTextLine(2, "Bias: %4d", HTMAGstartCal(HTMAG));
    PlaySound(soundBlip);
    while(bSoundActive);
    while(nNxtButtonPressed != kNoButton) EndTimeSlice();

    while(nNxtButtonPressed != kEnterButton) {
      eraseDisplay();

      nxtDisplayTextLine(1, "Reading");
      // Read the current calibration offset and display it
      nxtDisplayTextLine(2, "Bias: %4d", HTMAGreadCal(HTMAG));

      nxtDisplayClearTextLine(4);
      // Read the current rotational speed and display it
      nxtDisplayTextLine(4, "Mag:   %4d", HTMAGreadVal(HTMAG));
      nxtDisplayTextLine(6, "Press enter");
      nxtDisplayTextLine(7, "to recalibrate");
      wait1Msec(100);
    }
  }
}
void RightBasketFarBridge()
{
RightBasketFar();
goInches(2, speed);
goTurn(47, speed);
goInches(36, speed);
goInches(10,Minspeed);
wait1Msec(300);
goInches(2, Minspeed);
goTurn(92, speed);
goInches(10, speed);
goInches(1, -speed);
  servo[FrontHolder] = 140;
  wait1Msec(1500);
  goInches(4, MountainSpeed);
  servo[FrontHolder] = 0;
  goInches(29.25, MountainSpeed);
  while(1)
  {
    wait1Msec(3000);
    int xAxis;
    HTACreadX(Accel, xAxis); //stores the z value to the variable zAxis
    nxtDisplayCenteredTextLine(2, "X:"+xAxis);
    if (xAxis > 2)
    {
      goInches(.1, MountainSpeed);
    }
    else if (xAxis < -24)
    {
      goInches(.1, -MountainSpeed);
    }
    else
    {
      break;
    }


  }

}
Ejemplo n.º 19
0
//----main----//
task main ()
{
	nxtDisplayCenteredTextLine(3, "Pose Test");
	wait1Msec(500);
	initialisePose(); //set up
	iterate(stepSize); //run excitation etc
	currentDirection = 0; //set initial
  currentTheta = 0;
  changeTheta = 0;

  //display data
 displayMax();
    nxtDisplayTextLine(2, "Num Act.: %3d",numActive);
    nxtDisplayTextLine(4, "Direction: %1d", currentDirection);
    nxtDisplayTextLine(5, "currentTheta:%3d", currentTheta);
    nxtDisplayTextLine(6, "changeTheta:%3d", changeTheta);
	datalogging();
  while(totalClicks<1800)
	{
		alive(); //stop NXT from sleeping
    totalClicks += clicks;
    //drive(-100,190,50);
   // drive(50,180,50);

    pose3D(changeTheta,0.5);

    displayMax();
    nxtDisplayTextLine(2, "Num Act.: %3d",numActive);
    nxtDisplayTextLine(4, "Direction: %1d", currentDirection);
    nxtDisplayTextLine(5, "currentTheta:%3d", currentTheta);
    nxtDisplayTextLine(6, "changeTheta:%3d", changeTheta);
    clearEncoders(); //clear encoder count
    changeTheta=0;
    datalogging();

  }
  PlaySound(soundFastUpwardTones);
  while(bSoundActive) {}
  SaveNxtDatalog();
}
Ejemplo n.º 20
0
////////////////////////////////////////////////////////////////////////////////
//Select Row------------------------------------------------------------------//
////////////////////////////////////////////////////////////////////////////////
void selectRow()
{
	eraseDisplay();
	// Enable Top Line NXT Display (Bluetooth, NXT Name & Battery Status)
	//bNxtLCDStatusDisplay = true;
	while(true)
	{
		nxtDisplayCenteredTextLine(1,"DITU SAYS WEAR");
		nxtDisplayCenteredTextLine(2,"SAFETY GLASSES");
		nxtDisplayCenteredTextLine(4,"Peg Row:");
		//------------------------------------------------
		if(nNxtButtonPressed == 1)	// NXT Right Triangle Button
		{
			Row++;
			wait1Msec(400);
		}
		//-------------------------------------------------
		if(nNxtButtonPressed == 2)	// NXT Left Triangle Button
		{
			Row--;
			wait1Msec(400);
		}
		//---------------------------------------------------------------
		// Keep Row within a range of valid values
		if (Row > 2) Row = 2;
		if (Row < 0) Row = 0;
		switch (Row)
		{
		case 0: nxtDisplayCenteredTextLine(6, "Bottom Row");break;
		case 1: nxtDisplayCenteredTextLine(6, "Middle Row");break;
		case 2: nxtDisplayCenteredTextLine(6, "Top Row");break;
		default: nxtDisplayCenteredTextLine(6, "Error");break;
		}
		//---------------------------------------------------------------
		if(nNxtButtonPressed == 3)	// NXT Orange Button
		{																																				////////////////	You  need to return a variable
			wait1Msec(400);																										////////////////	that selects the auto program
			break;																																////////////////	for later. 			-Jos :)
		}
		//---------------------------------------------------------------
	}
}
Ejemplo n.º 21
0
task main()
{
  nNxtButtonTask  = -2;
  nxtDisplayCenteredTextLine(0, "Codatex");
  nxtDisplayCenteredBigTextLine(1, "RFID");
  nxtDisplayCenteredTextLine(3, "Test 2");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);

  eraseDisplay();
  nxtDisplayCenteredTextLine(3, "Start single");
  nxtDisplayCenteredTextLine(4, "reading loop");
  wait1Msec(2000);
  eraseDisplay();

  // Set up the sensor for continuous readings.
  CTRFIDsetContinuous(CTRFID);

  // loop for transponder readings with continuous read function
  while(nNxtButtonPressed == kNoButton) {
    // read the transponder
    if (!CTRFIDreadTransponder(CTRFID, transponderID)) {
      eraseDisplay();
      nxtDisplayTextLine(3, "Error reading");
      nxtDisplayTextLine(4, "from sensor!");
      wait10Msec(5000);
      StopAllTasks();
    }
    nxtDisplayCenteredTextLine(3, "Transponder ID:");
    nxtDisplayCenteredTextLine(4, "%s", transponderID);

    // Be sure to add about 200ms after each read
    // or you end up getting 0000000000 as a transponder address
    wait1Msec(200);
  }
}
Ejemplo n.º 22
0
void movesStart (WaitFor waitForRoutine, float waitForParam)
{
	nxtDisplayCenteredTextLine(5, "Starting");

	if (moveModeTiming == MMOneMoveAtATime || stepThroughMode == stepThroughModeOn) {
	} else {
		switch (waitForRoutine) {
		case WFTouch:
				waitForTouch();
				break;
		case WFLoud:
			waitForLoud(waitForParam);
			break;
		case WFTime:
			waitForTime(waitForParam);
			break;
		case WFNothing:
			default:
			break;
		}
	}
}
Ejemplo n.º 23
0
int time(){
	int d = 1;
	int wait_time = 0;
	nxtDisplayTextLine(1, "L_ARROW = +time");
	nxtDisplayTextLine(2, "R_ARROW = Determine Position");
	nxtDisplayTextLine(5, "Delay Time?");
	bool select = false;
	while(!select){

		nxtDisplayCenteredTextLine(3, "%d", d);
		if(nNxtButtonPressed == 2){         //Left arrow is button 2
			wait10Msec(50);
			wait_time = 100*d;
			d++;
			select = false;
			}else if(nNxtButtonPressed == 1){    // Right arow is button 1
			wait10Msec(50);
			select = true;
		}
	}
	return wait_time;
}
Ejemplo n.º 24
0
void initializeRobot()
{

  // Place code here to sinitialize servos to starting positions.
  // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

int black;
wait10Msec(200);
black=SensorValue[colorport];
wait10Msec(50);
black=SensorValue[colorport];
colorMid=(black+(black/2));
StringFormat(disp,"%d %d", black, colorMid);
nxtDisplayCenteredTextLine(2, disp );

	//PlayTone(850, 100);
	//int white;
	//white= SensorValue[colorport];
	//wait10Msec(200);
	//white= SensorValue[colorport];
 // StringFormat(disp,"White is %d", white);
 // nxtDisplayCenteredTextLine(2, disp );
	//wait10Msec(200);

	//PlayTone(800, 100);
	//wait10Msec(200);
	//int black= SensorValue[colorport];
 // StringFormat(disp,"Black is %d", black);
 // nxtDisplayCenteredTextLine(2, disp );
	//wait10Msec(200);

	//colorMid = (white+black)/2;
 // StringFormat(disp,"Mid is %d", colorMid);
 // nxtDisplayCenteredTextLine(2, disp );
	//PlayTone(750, 100);
	//wait10Msec(500);

  return;
}
Ejemplo n.º 25
0
int JedkNejblizsimu(){
	dokoncil = false;
	while(!dokoncil){
		HledejNejkratsiCestu();
		string cesta;
		char ccesta[20];
		for(int i=0; i<20 && znovu == false; i++) ccesta[i] = nejkratsiCesta[i];
		StringFromChars(cesta, ccesta);
		nxtDisplayCenteredTextLine(0, cesta);
		for(int i=0; i<cestaSize; i++){
			if(nejkratsiCesta[i] == 0){
				dokoncil = true;
				break;
			}
			else if(nejkratsiCesta[i] == 'R'){
				cleanExit = true;
				Rovne(false);
			}
			else if(nejkratsiCesta[i] == '0'){
				if(PoziceRobota[2] == 3) VpravoC();
				else if(PoziceRobota[2] == 1) VlevoC();
				else{ Vlevo(); Vlevo();}
			}else if(nejkratsiCesta[i] == '1'){
				if(PoziceRobota[2] == 0) VpravoC();
				else if(PoziceRobota[2] == 2) VlevoC();
				else{ Vlevo(); Vlevo();}
			}else if(nejkratsiCesta[i] == '2'){
				if(PoziceRobota[2] == 1) VpravoC();
				else if(PoziceRobota[2] == 3) VlevoC();
				else{ Vlevo(); Vlevo();}
			}else if(nejkratsiCesta[i] == '3'){
				if(PoziceRobota[2] == 2) VpravoC();
				else if(PoziceRobota[2] == 0) VlevoC();
				else{ Vlevo(); Vlevo();}
			}
		}
	}
	return nejkratsiCesta_size();
}
Ejemplo n.º 26
0
int getSteps()	{
	bool cont = true;
	int nSteps = 0;

	nxtDisplayCenteredBigTextLine(0, "#STEPS:");
	while(cont)	{
		if(nNxtButtonPressed == B_LEFT)	{
			nSteps--;
		}
		else if(nNxtButtonPressed == B_RIGHT)	{
			nSteps++;
		}
		else if(nNxtButtonPressed == B_ORANGE)	{
			cont = false;
		}

		nxtDisplayCenteredTextLine(3, "%i", nSteps);
		wait1Msec(75);
	}

	return nSteps;
}
task main()
{

	int distance_in_cm =30;   // Create variable 'distance_in_cm' and initialize it to 20(cm).
	while (true)
	{

		nxtDisplayCenteredTextLine(7, "%d", SensorValue[sonarSensor]);

		if (SensorValue[sonarSensor] > distance_in_cm)   // While the Sonar Sensor readings are less than the specified, 'distance_in_cm':
		{
			motor[motorA] = 35;                     // Motor B is run at a 75 power level
			motor[motorB] = 35;                     // Motor C is run at a 75 power level

		}

		else
		{
			motor[motorA] = 0;
			motor[motorB] = 0;
		}
	}
}
Ejemplo n.º 28
0
task main()
{
	initializeRobot();

	while(true)

	{
		getJoystickSettings(joystick);

		if(joy1_TopHat > 0)
		{
			for (int i = 1; i < 10; i++)
			{
				if (joy1Btn (i) == 1)

				{
					nxtDisplayCenteredTextLine( 1, "Button %d pushed.",i );

			  }
		  }
	  }
  }
}
Ejemplo n.º 29
0
task main()
{
 	initializeRobot();
 	initialize_gyro();
	starttask(process_gyro);


	while(true)
	{
		nxtDisplayCenteredTextLine(3, "A gyro=%d", gyro.total/1000.0);
	}
	//move(1, 22.5);
	//wait10Msec(500);
	//move(-1,22.5);

 //move forward, turn 45 degrees, move forward
 //move(1, 24);
 //wait10Msec(50);
 //move(1, 0);
 //turngyro_left(45.0, 50);
 //move(1, 33.941);

}
Ejemplo n.º 30
0
task main()
{
  ubyte msg=0;
  SensorType[TOUCH1]=sensorTouch;
  SensorType[TOUCH2]=sensorTouch;
  SensorType[TOUCH3]=sensorTouch;

  checkLink();

  PlayTone(400,100);
  eraseDisplay();
  while(true){
    //do not attempt to do encoding until you know your bot
    //   is able to communicate and send the simple incrementing number over
    //   to the worker bot
    //msg=encodeByAdd();
    //msg=encodeByBits();
    msg = (msg<255 ?  ++msg : 0); //simply just send 1, 2, ... up to 255, then recycle
    nxtDisplayCenteredTextLine(3,"%d", msg);
    sndOver(msg);
    wait1Msec(20);
  }
}