void move_down(struct game_t *game) { rotate_clockwise(game); move_left(game); rotate_clockwise(game); rotate_clockwise(game); rotate_clockwise(game); }
void LocalPlanner::resolve_heading(){ float delta; delta = new_heading - current_heading; if (((-(2 * PI) < delta) && (delta < -(PI))) || ((0 < delta) && (delta < PI))) rotate_counterclockwise(delta); else if (((-(PI) < delta) && (delta < 0)) || ((PI < delta) && (delta < (2 * PI)))) rotate_clockwise(delta); else if (delta == PI || delta == -(PI)) rotate_clockwise(delta); }
void Node::balance_function(Node *&root) { if(!root) return; int balance_factor = get_balance(root); //TODO remove //cout << "balance_factor at : " << root->word // << " is " << balance_factor << endl; if(balance_factor == 2) { int left_balance = get_balance(root->left); //left has more than right //so left should become root if(left_balance == 0) { cout << "this shouldn't happen, if it does we have a problem" << endl; } if(left_balance == 1) { rotate_clockwise(root); } if(left_balance == -1) { rotate_counter_clockwise(root->left); rotate_clockwise(root); } } if(balance_factor == -2) { int right_balance = get_balance(root->right); //right has more than left if(right_balance == 0) { cout << "this shouldn't happen, if it does we have a problem" << endl; } if(right_balance == 1) { rotate_clockwise(root->right); rotate_counter_clockwise(root); } if(right_balance == -1) { rotate_counter_clockwise(root); } } return; }
void quadtree::rotate_clockwise(std::unique_ptr<node> & subroot) { if(!subroot) return; subroot->northeast.swap(subroot->northwest); subroot->northwest.swap(subroot->southwest); subroot->southwest.swap(subroot->southeast); rotate_clockwise(subroot->northwest); rotate_clockwise(subroot->northeast); rotate_clockwise(subroot->southwest); rotate_clockwise(subroot->southeast); }
task main() { waitForStart(); // Wait for the tele-op period to begin nMotorEncoder(motorLift1) = 0; // Reset the motor encoders for the arm servoTarget(clawL) = 225; // Initialize the claw to be open servoTarget(clawR) = 60; PlaySoundFile("Leroy.rso"); // Shout "LEEROY JENKINS!", just for fun wait1Msec(10); // Wait one tenth of a second while (true) { getJoystickSettings(joystick); // Read the value of the joysticks nxtDisplayTextLine(6, "Encoder: %d", nMotorEncoder[motorLift1]); // Display the value of the arm encoder // The following code makes the directional pad on controller 1 give precise digital control of the drivetrain: if (joystick.joy1_TopHat == 0) // If "up" on the directional pad is pressed: { go_forward(25); // Go forward at 25% speed } else if (joystick.joy1_TopHat == 1) // Else if "top right" on the directional pad is pressed: { strafe_forward_right(25); // Strafe diagonally forward and to the right at 25% speed } else if (joystick.joy1_TopHat == 2) // Else if "right" on the directional pad is pressed: { strafe_right(25); // Strafe to the right at 25% speed } else if (joystick.joy1_TopHat == 3) // Else if "bottom right" on the directional pad is pressed: { strafe_backward_right(25); // Strafe diagonally backward and to the right 25% speed } else if (joystick.joy1_TopHat == 4) // Else if "down" on the directional pad is pressed: { go_backward(25); // Go backward 25% speed } else if (joystick.joy1_TopHat == 5) // Else if "bottom left" on the directional pad is pressed: { strafe_backward_left(25); // Strafe diagonally backward and to the left 25% speed } else if (joystick.joy1_TopHat == 6) // Else if "left" on the directional pad is pressed: { strafe_left(25); // Strafe left 25% speed } else if (joystick.joy1_TopHat == 7) // Else if "top left" on the directional pad is pressed: { strafe_forward_left(25); // Strafe diagonally forward and to the left 25% speed } else if (joy1Btn(5)) // Else if button 6 is pressed: { rotate_clockwise(25); // Rotate the robot clockwise 25% speed } else if (joy1Btn(6)) // Else if button 5 is pressed: { rotate_counter_clockwise(25); // Rotate the robot counter-clockwise 25% speed } // The following code makes the joysticks on controller 1 give analogue control of the drivetrain: else { motor[motorFL] = scale_motor(joystick.joy1_y1 + joystick.joy1_x1 + joystick.joy1_x2); // Scale the motors to the average motor[motorFR] = scale_motor(joystick.joy1_y1 + -joystick.joy1_x1 - joystick.joy1_x2); //of the left joystick Y value and motor[motorBR] = scale_motor(joystick.joy1_y1 + joystick.joy1_x1 - joystick.joy1_x2); //the right joystick X value motor[motorBL] = scale_motor(joystick.joy1_y1 + -joystick.joy1_x1 + joystick.joy1_x2); } // The following code assigns the shoulder buttons on controller 2 to open and close the claw: if (joy2Btn(5)) { servoTarget(clawL) = 55; // If button 5 is pressed on controller 2, close the claw servoTarget(clawR) = 170; } else if (joy2Btn(6)) { servoTarget(clawL) = 115; // If button 6 is pressed on controller 2, open the claw servoTarget(clawR) = 100; } else if (joy2Btn(8)) { servoTarget(clawL) = ServoValue(clawL) + 1; // While button 7 is held, slowly close the claw servoTarget(clawR) = ServoValue(clawR) - 1; } else if (joy2Btn(7)) { servoTarget(clawL) = ServoValue(clawL) - 1; // While button 8 is held, slowly open the claw servoTarget(clawR) = ServoValue(clawR) + 1; } else { servoTarget(clawL) = ServoValue(clawL); // Otherwise, do not move the claw servoTarget(clawR) = ServoValue(clawR); } // The following code gives analogue control of the arm with the joystick, and assigns buttons 1-4 to move the arm to their respective rows on the scoring rack if (joy2Btn(1)) // If button 1 is pressed, move the arm to the lowest row on the scoring rack { moveArm(level1Value); } else if (joy2Btn(2)) // If button 2 is pressed, move the arm to the middle row on the scoring rack { moveArm(level2Value); } else if (joy2Btn(3)) // If button 3 is pressed, move the arm to the top row on the scoring rack { moveArm(level3Value); } else if (joy2Btn(4)) // If button 4 is pressed, lower the arm all the way { moveArm(0); } else { motor[motorLift1] = (joystick.joy2_y1 / 12); // Otherwise, control the arm with joystick 1 on controller 2 motor[motorLift1] = (joystick.joy2_y1 / 24); // Or control the arm at half speed with joystick 2 on controller 2 // Note: these values are divided by 12 and 24 to bring the arm speed down to a reasonable level } } }
void quadtree::rotate_clockwise() { rotate_clockwise(root_); }