task main() { initializeRobot(); waitForStart(); // Wait for the beginning of autonomous phase. //Start(); /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// //// //// //// Add your robot specific autonomous code here. //// //// //// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// Start(); Move(10, 50.0); // drive forward distance inches wait10Msec(10); Turn(45);// turn counterclockwise turn degrees motor[Left_Side] = 10; motor[Right_Side] = -10; wait10Msec(10); Move(100, 0.0); // drive forward distance inches wait10Msec(20); Turn(90); wait10Msec(100); //servo[L_Wrist] = 235; // servo[R_Wrist] = 20; wait10Msec(200); }
void PenFollowAlgorithm(void) { unsigned long start_time; int pen_dist=30, dist, detected = False, lost = False, infi = 60, played = False; // put pen facing wheel #1 // turn robot to the right until it finds the center of the pen Turn(Right, Slow); DisplayTxt("Scanning..."); do { dist = Sensor_To_Range(Sensor(3)); if (dist <= pen_dist) detected = True; } while ( (detected == False) && (SmartWait(1)==0) ); StopRobot(); // stop robot // begin tracking loop do { // ADJUST ANGULAR POSITION dist = Sensor_To_Range(Sensor(3)); if (dist > infi) { // target lost turn left/right played = False; Turn(Right,Slow); Wait(50); StopRobot(); // turn right for awhile dist = Sensor_To_Range(Sensor(3)); if (dist > infi) { // target is not to the right, Turn(Left,Slow);// turn left start_time = 0; do { dist = Sensor_To_Range(Sensor(3)); } while ((start_time++ < 1000) && (dist > infi) && (SmartWait(1)==0) ); // turn until found dist = Sensor_To_Range(Sensor(3)); if (dist > infi) { lost = True; break; } StopRobot(); } } dist = Sensor_To_Range(Sensor(3)); // ADJUST LINEAR POSITION if ( (dist < infi) && (dist < (pen_dist-5)) ) { // too close to target played = False; Move(RToServo3); do { dist = Sensor_To_Range(Sensor(3)); if (dist > infi) // lost angular tracking break; } while (dist < pen_dist); // get dist to pen_dist StopRobot(); } if ( (dist < infi) && (dist > (pen_dist+5)) ) { // too far played = False; Move(ToServo3); do { dist = Sensor_To_Range(Sensor(3)); if (dist > infi) // lost angular tracking break; } while (dist > pen_dist); // get dist to pen_dist StopRobot(); } if ( (dist < (pen_dist+5)) && (dist > (pen_dist-5)) && (played == False) ) { printf("Yep\n"); played = True; } } while ( (lost == False) && (SmartWait(10)==0) ); StopRobot(); }
task main() { waitForStart(); Forward(1440, 100); Turn(720, 100, right); Forward(1440, 100); Turn(720,100,right); }
void Game_Character::TurnAwayFromHero() { int sx = DistanceXfromPlayer(); int sy = DistanceYfromPlayer(); if ( std::abs(sx) > std::abs(sy) ) { Turn((sx > 0) ? Right : Left); } else { Turn((sy > 0) ? Down : Up); } }
void Game_Character::TurnTowardHero() { int sx = DistanceXfromPlayer(); int sy = DistanceYfromPlayer(); if ( std::abs(sx) > std::abs(sy) ) { Turn((sx > 0) ? Left : Right); } else { Turn((sy > 0) ? Up : Down); } }
/* Main()*/ int main(int argc, const char **argv) { // Create a client object and connect to the server; the server must // be running on "localhost" at port 6665 client = playerc_client_create(NULL, "gort", 9876); if (playerc_client_connect(client) != 0) { fprintf(stderr, "error: %s\n", playerc_error_str()); return -1; } // Create a bumper proxy (device id "bumper:0" and subscribe // in read mode bumper = playerc_bumper_create(client, 0); if(playerc_bumper_subscribe(bumper,PLAYERC_OPEN_MODE)!= 0) { fprintf(stderr, "error: %s\n", playerc_error_str()); return -1; } // Create a position2d proxy (device id "position2d:0") and susbscribe // in read/write mode position2d = playerc_position2d_create(client, 0); if (playerc_position2d_subscribe(position2d, PLAYERC_OPEN_MODE) != 0) { fprintf(stderr, "error: %s\n", playerc_error_str()); return -1; } // Enable the robots motors playerc_position2d_enable(position2d, 1); playerc_client_read(client); // Point 1 to Point 2 Move(client, MOVE1, ANGLE1); Turn(client, TURN1); // Point 2 to Point 3 Move(client, MOVE2, ANGLE2); Turn(client, TURN2); // Point 3 to Point 4 Move(client, MOVE3, ANGLE3); Turn(client, TURN3); // Point 4 to Point 5 Move(client, MOVE4, ANGLE4); // Shutdown and tidy up playerc_position2d_unsubscribe(position2d); playerc_position2d_destroy(position2d); playerc_client_disconnect(client); playerc_client_destroy(client); return 0; }
task main() { initializeRobot(); waitForStart(); // Wait for the beginning of autonomous phase. servo[IRS_1] = 160; int DistFrom = 43; int Deadband = 2; float COUNTS_PER_INCH = 90.55; Move(5,25); wait10Msec(55); servo[Block_Chuck] = 255; wait10Msec(55); servo[Block_Chuck] = 0; wait10Msec(55); nMotorEncoder[L_Motor] = 0; nMotorEncoder[L_Motor] = 0; while(nMotorEncoder[L_Motor] < 29 * COUNTS_PER_INCH && nMotorEncoder[R_Motor] < 29 * COUNTS_PER_INCH) { motor[L_Motor] = 100; motor[R_Motor] = 100; } wait10Msec(20); Turn(90); wait10Msec(55); Move(50, 100); wait10Msec(55); Move(-50, 100); wait10Msec(55); Turn(-90); wait10Msec(55); Move(-15, 75); wait10Msec(55); Turn(90); wait10Msec(55); Move(7, 100); wait10Msec(55); //Move(50, 100); } // End main task
task main() { initializeRobot(); waitForStart(); // Wait for the beginning of autonomous phase. servo[sgrab] = 185; servo[srelease] = 140; wait10Msec(55); Move(100,40); wait10Msec(50); Turn(20); wait10Msec(55); Ultra_Seek(21,48); wait10Msec(55); Turn(6); wait10Msec(55); Move(14,10); wait10Msec(55); servo[sgrab] = 255; wait10Msec(40); Turn(-10); wait10Msec(40); Move(-15,75); wait10Msec(55); lift_move(18); wait10Msec(55); servo[srelease] = 255; wait10Msec(150); Turn(-180); wait10Msec(40); //servo[sgrab] = 100; wait10Msec(40); }
task main() { StartTask(Arm_hold); initializeRobot(); waitForStart(); // Wait for the beginning of autonomous phase. nMotorEncoder[R_Motor] = 0; nMotorEncoder[L_Motor] = 0; Move (1,75); wait10Msec(55); Arm_move(-100); wait10Msec(55); // Hold_enable = true; servo[Bucket_Release] = 255; wait10Msec(55); servo[Bucket_Release] = 0; wait10Msec(55); Arm_move(100); wait10Msec(55); Move(-1, 75); wait10Msec(55); Turn(40); wait10Msec(55); Move(30,100); wait10Msec(55); Turn(-85); wait10Msec(55); Move(30,100); wait10Msec(55); /*Turn(-90); wait10Msec(55); Move(80,100); wait10Msec(55);*/ } // End main task
void StateCharacterTurning::Update(float timeStep) { StateCharacterGrounded::Update(); RigidBody* body = pawn_->GetBody(); AnimationController* animCtrl = static_cast<PawnAnimated*>(pawn_)->GetAnimationController(); //apply a force to slow it down further, since we are changing direction body->ApplyImpulse(moveDir_ * pawn_->GetMoveForce() *0.25);//0.25 to dampen it //get the speed that we are travelling, that will determine when we turn around if(!flipped_) { //before we are flipped around, we drive the turning animation //float spd = pawn_->GetPlaneVelocity().Length(); //float turnTime = Fit(spd,0.0f,speed_,1.0f,0.0f); animCtrl->PlayExclusive("Models/Man/MAN_TurnSkidGunning.ani", 0,false, 0.1f); //animCtrl->SetTime("Models/Man/MAN_TurnSkidGunning.ani",turnTime); if(animCtrl->IsAtEnd("Models/Man/MAN_TurnSkidGunning.ani")) { Turn(); animCtrl->Play("Models/Man/MAN_TurnSkidGunningFlipped.ani", false, 0.0f); flipped_=true; } } else { animCtrl->Play("Models/Man/MAN_TurnSkidGunningFlipped.ani", false, 0.0f); //now that we are flipped we can set it to the next state too pawn_->SetState( new StateCharacterRunning(context_) ); } }
void Fig::Init(int fig0) { int p=0,q=1; arr0[0]=fig0; while(p<q) { int a=arr0[p++]; for(int u=0;u<2;u++) { int b=Turn(a,u); int i; for(i=0;i<q;i++) if(arr0[i]==b) break; if(i==q) arr0[q++]=b; } } for(p=0;p<q;p++) if((arr0[p]&XHIGH)==0) arr0[q++]=arr0[p]<<1; for(p=0;p<q;p++) if((arr0[p]&YHIGH)==0) arr0[q++]=arr0[p]<<3; for(p=0;p<q;p++) if((arr0[p]&ZHIGH)==0) arr0[q++]=arr0[p]<<9; Init(q,arr0); }
void Camera::FreeFlyControl(const sf::Window& window, sf::Time elapsedTime) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { Move(GEAR::LEFT, elapsedTime.asSeconds()); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { Move(GEAR::RIGHT, elapsedTime.asSeconds()); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { Move(GEAR::BACKWARD, elapsedTime.asSeconds()); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { Move(GEAR::FORWARD, elapsedTime.asSeconds()); } sf::Vector2u screenSize = window.getSize(); sf::Vector2i windowCenterPos(screenSize.x/2,screenSize.y/2); sf::Vector2i mouseOffset = sf::Mouse::getPosition(window) - windowCenterPos; Turn(mouseOffset.x * SENSITIVITY, -mouseOffset.y * SENSITIVITY); }
int Connect4Player::Chance(int player) { system("cls"); ShowBoard(); int row=PlayerMove(Turn(),player); while(!(row>=0)) { system("cls"); cout<<" Wrong move try again\n "; system("Pause"); system("cls"); ShowBoard(); row=PlayerMove(Turn(),player); } return row; }
void Open() { cout << "TurnKey: -> Open." << endl; Insert(); Turn(); Remove(); }
void PrimeAuto() { Move(67,50); // dist,pow wait10Msec(10); initialize(); Turn(-40, 9502); // going for 45 inside of left turn, overshoots // The direction of turn is determined only by altering power here, the sign of the distance has no effect because it is nulled during Abs() along with "sum" in the while statement wait10Msec(10); Move(36,50); wait10Msec(10); initialize(); Turn(40,13031); //going for 20 inside of right turn // pow, angle wait10Msec(10); Move(28,50); wait10Msec(7); IRbeg(); }
void GameBoard::HighScore() { if (Turn() == 2) { ++p2Score; } else { ++p1Score; } }
task main() { initializeRobot(); waitForStart(); // Wait for the beginning of autonomous phase. motor[R_Motor] = 75; motor[L_Motor] = 75; wait10Msec(50); motor[R_Motor] = 0; motor[L_Motor] = 0; wait10Msec(50); Turn(45); wait10Msec(100); motor[R_Motor] = 0; motor[L_Motor] = 0; wait10Msec(50); motor[R_Motor] = -75; motor[L_Motor] = -75; wait10Msec(50); motor[R_Motor] = 0; motor[L_Motor] = 0; }
void UpdateAI(const uint32 diff) { if (!m_creature->SelectHostileTarget() || !m_creature->getVictim()) return; if (FlamingCinder_Timer < diff) { for(int i = 0; i < CINDER_TARGETS; i++) { if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM,0)) DoCast(pTarget, m_bIsRegularMode ? SPELL_FLAMING_CINDER_N : SPELL_FLAMING_CINDER_H); } FlamingCinder_Timer = 12000; }else FlamingCinder_Timer -= diff; if (bRotate) { if (Rotate_Timer <= diff) { Turn(); Rotate_Timer = 750; }else Rotate_Timer -= diff; } if (BurningBreath_Timer < diff) { DoCast(m_creature,m_bIsRegularMode ? SPELL_BURNING_BREATH_N : SPELL_BURNING_BREATH_H); BurningBreath_Timer = 45000; Rotate_Timer = 750; bRotate = true; Turn(); }else BurningBreath_Timer -= diff; if (MeteorFists_Timer < diff) { DoCast(m_creature,m_bIsRegularMode ? SPELL_METEOR_FISTS_AURA_N : SPELL_METEOR_FISTS_AURA_H); MeteorFists_Timer = 30000; }else MeteorFists_Timer -= diff; if (m_creature->HasAura(m_bIsRegularMode ? SPELL_METEOR_FISTS_AURA_N : SPELL_METEOR_FISTS_AURA_H)) { DoCast(m_creature->getVictim(),m_bIsRegularMode ? SPELL_METEOR_FISTS_N : SPELL_METEOR_FISTS_H); } DoMeleeAttackIfReady(); }
task main() { int distance; nMotorEncoder[mRight] = 0; while(SensorValue(IR) != 5) { motor[mLeft] = 30; motor[mRight] = 30; } motor[mLeft] = 0; motor[mRight] = 0; wait1Msec(500); distance = nMotorEncoder[mRight]; Forward(100, 30); wait1Msec(500); servo[AutoHook] = 0; wait1Msec(1000); servo[AutoHook] = 250; wait1Msec(500); Backward(distance+100, 30); wait1Msec(500); Turn(1640, 100, right); motor[mRight] = 0; motor[mLeft] = 0; wait1Msec(500); //goes backwards and towards the ramp Backward(4000,50); motor[mRight] = 0; motor[mLeft] = 0; wait1Msec(500); //turns towards the ramp Turn(1900, 100, right); motor[mRight] = 0; motor[mLeft] = 0; wait1Msec(500); //goes onto the ramp Backward(4500,100); }
task main() { initializeRobot(); waitForStart(); // Wait for the beginning of autonomous phase. servo[tilt] = 35; Move(-90,75); wait10Msec(50); Turn(-90); wait10Msec(80); Move(-12,25); wait10Msec(80); Turn(-45); wait10Msec(50);
bool GameBoard::UpdateBorder(int newValue) { int row = newValue / 3; int col = newValue % 3; if (ValidateMark(row, col)) { boarder[row][col] = Turn(); return true; } return false; }
//*********************************************************************** void VideoFx::OnVideoDraw(LPBITMAPINFOHEADER lpFormat, LPTR lpData) //*********************************************************************** { if (iEvent == 0) return; if (iEvent == EVENT_LEFT) Turn(lpFormat, lpData, EVENT_LEFT); else if (iEvent == EVENT_RIGHT) Turn(lpFormat, lpData, EVENT_RIGHT); else if (iEvent == EVENT_DOWN) Turn(lpFormat, lpData, EVENT_DOWN); else if (iEvent == EVENT_UP) Invert(lpFormat, lpData); }
// Used only when retreating Action Agent::OrientAndMoveTo( Heading dir ) { // if already oriented in direction, move to node if ( facing == dir ) { y += GetFaceY(); x += GetFaceX(); return FORWARD; } // otherwise, turn if ( ( facing + 3 ) % 4 == dir ) { return Turn( LEFT ); } return Turn( RIGHT ); }
void Mouse::Turn(Path_new * newPath) { // make path the new complete guess Path //Path_new *newCompleteGuessPath = new Path_new(); //get room to continue to Room * nextRoom = newPath->Rooms()->front(); // Turn toward the room Turn(nextRoom); }
// turn towards or move to best nearby node (not coming home) Action Agent::FindBestNode() { sucked = false; score--; if ( ++ticker == RETREAT_TICKER ) { retreating = true; return Turn( LEFT ); } if ( toTurn ) { int temp = toTurn; toTurn = 0; return Turn( (Action) temp ); } int leftDir = ( facing + 3 ) % 4; int rightDir = ( facing + 1 ) % 4; int crossDir = ( facing + 2 ) % 4; Node best, cur; int dir = facing; turned = false; // node ahead cur = room[x + GetFaceX()][y + GetFaceY()]; if ( cur.type == UNVISITED ) return FORWARD; else best = room[x + GetFaceX()][y + GetFaceY()]; // left node cur = room[x + GetFaceX( leftDir )][y + GetFaceY( leftDir )]; if ( cur.type == UNVISITED ) return Turn( LEFT ); else ChooseBest( best, cur, dir, leftDir ); // right node cur = room[x + GetFaceX( rightDir )][y + GetFaceY( rightDir )]; if ( cur.type == UNVISITED ) return Turn( RIGHT ); else ChooseBest( best, cur, dir, rightDir ); // cross node cur = room[x + GetFaceX( crossDir )][y + GetFaceY( crossDir )]; if ( cur.type == UNVISITED ) return Turn( RIGHT ); else ChooseBest( best, cur, dir, crossDir ); // return appropriate action if ( dir == facing ) return FORWARD; if ( dir == leftDir ) return Turn( LEFT ); if ( dir == rightDir ) return Turn( RIGHT ); return Turn( RIGHT, true ); // crossDir }
task main() { initializeRobot(); waitForStart(); // Wait for the beginning of autonomous phase. clearDebugStream(); Move(16.01, 0.75); wait10Msec(10); Turn(-(180 - 110.55)); wait10Msec(10); Move(46.11, 1); }
void executePlan3() { Turn(-90); rotateSonar(-90); Forward(40); ForwardWallFollow(false); Forward(25); Turn(-90); Forward(40); AtWaypoint(); // Waypoint 2 Forward(-40); Turn(90); Forward(40); ForwardWallFollow(false); Forward(25); Turn(-90); Forward(40); AtWaypoint(); // Waypoint 1 Forward(-40); Turn(-90); Forward(40); rotateSonar(180); //Skip past middle gap ForwardWallFollow(true); Forward(50); ForwardWallFollow(true); Forward(25); Turn(90); Forward(40); AtWaypoint(); // Waypoint 3 }
void moveOutOfStartBlock() { int i; int startIdx = -1; int endIdx = -1; int dists[NO_BINS]; //Determine angle to turn float ang = (float) (360/NO_BINS)+SONAR_TURN_EXTRA; // Spin sonar and take readings for (i=0; i < NO_BINS; i++) { rotateSonar(ang); // Save dist in loc_sig instance ls dists[i] = SensorValue[sonarSensor]; //writeDebugStreamLine("DIST: %d %d", i, dists[i]); if (dists[i] > BOX_THRESHOLD && dists[i] < SENSOR_MAX && startIdx == -1) { startIdx = i; } else if (startIdx != -1 && endIdx == -1 && dists[i] < BOX_THRESHOLD) { endIdx = i; } } if (endIdx == -1) endIdx = NO_BINS; // Unspin sonar back to start position wait1Msec(500); rotateSonar(-360); //writeDebugStreamLine("S: %d E: %d", startIdx, endIdx); int idx = (startIdx+endIdx)/2; float angleToTurn = idx*360/NO_BINS; writeDebugStreamLine("ANGLE: %f", angleToTurn); // Ensure we turn smallest distance possible angleToTurn -= 20; if (angleToTurn > 180) angleToTurn = angleToTurn-360; if (angleToTurn < 0) angleToTurn -= 10; Turn(angleToTurn); Forward(40); }
task main() { waitForStart(); //wait1Msec(20000); nMotorEncoder[Right] = 0; Forward(3100,70); nMotorEncoder[mLift] = 0; while(nMotorEncoder[mLift] < 3800) { motor[mLift] = 50; } motor[mLift] = 0; Forward(700,70); wait1Msec(1000); Turn(720,100,right); while (getSensorReading()>2){ motor[Right] = 70; motor[Left] = 70; } motor[Right]=0; motor[Left]=0; motor[mDispenser] = -50; wait1Msec(200); motor[mDispenser] = 50; wait1Msec(200); motor[mDispenser] = 0; wait1Msec(500); Forward(5700,100); motor[mIntake] = 100; wait10Msec(10); motor[mIntake] = 0; while (getSensorReading>2){ motor[Right] = 70; motor[Left] = 70; } motor[Right]=0; motor[Left]=0; motor[mDispenser] = -50; wait1Msec(200); motor[mDispenser] = 50; wait1Msec(200); motor[mDispenser] = 0; wait1Msec(500); Backward(1700,70); wait1Msec(500); }
task main() { initializeRobot(); //Executes all code in the initializeRobot() function StartTask( watchdog ); //Start watchdog task which is a failsafe for the Move function waitForStart(); //Wait for the beginning of autonomous phase wait10Msec(25); //Pause for 250 miliseconds Move(1,40); //Move away from the wall 1 inch at 40% power wait10Msec(25); //Pause for 250 miliseconds motor[block_arm] = 100; //Give 100% power to the arm motor wait10Msec(66); //Allow the arm to run for 660 miliseconds motor[block_arm] = 0; //Kill the power to the arm motor wait10Msec(25); //Pause for 250 miliseconds servo[Claw] = 10; //Move block release servo to open position (10 degrees) allowing it to drop the block wait10Msec(100); //Pause for 1000 miliseconds to allow the block to fall motor[block_arm] = -100; //Give 100% power to the arm again but in the oppisite direction wait10Msec(35); //Allow the arm to move back to a closed position motor[block_arm] = 0; //Kill the power to the arm motor wait10Msec(25); //Pause for 250 miliseconds Turn(-80); //Turn 80 degrees away from the bucket wait10Msec(25); //Pause for 250 miliseconds Move(22,75); //Move 22 inches towards the ramp at 75% power wait10Msec(25); //Pause for 250 miliseconds Turn(125); //Turn 55 degrees towards the ramp wait10Msec(25); //Pause for 250 miliseconds Move(53,75); //Move onto the ramp for the end of the autonomous phase wait10Msec(25); //Pause for 250 miliseconds }