void person() { torso(); glPushMatrix(); head(); glPopMatrix(); glPushMatrix(); upper_right_arm(); lower_arm(); hand(); glPopMatrix(); glPushMatrix(); upper_left_arm(); lower_arm(); hand(); glPopMatrix(); glPushMatrix(); upper_right_leg(); lower_leg(); glPopMatrix(); glPushMatrix(); upper_left_leg(); lower_leg(); glPopMatrix(); }
void renderScene() { // Clear framebuffer & depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Enable lighting glEnable(GL_LIGHTING); //Set the material properties glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, emerald_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, emerald_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, emerald_specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, emerald_shininess); // Reset Modelview matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Set view position & direction // (Camera at (0,0,5) looking down the negative Z-axis) gluLookAt(0, 0, 5, 0, 0, -1, 0, 1, 0); torso(); glPushMatrix(); head(); glPopMatrix(); glPushMatrix(); upper_right_arm(); lower_arm(); hand(); glPopMatrix(); glPushMatrix(); upper_left_arm(); lower_arm(); hand(); glPopMatrix(); glPushMatrix(); upper_right_leg(); lower_leg(); glPopMatrix(); glPushMatrix(); upper_left_leg(); lower_leg(); glPopMatrix(); glutSwapBuffers(); }
// We are going to override (is that the right word?) the draw() // method of ModelerView to draw out RobotArm void RobotArm::draw() { /* pick up the slider values */ float theta = VAL( BASE_ROTATION ); float phi = VAL( LOWER_TILT ); float psi = VAL( UPPER_TILT ); float cr = VAL( CLAW_ROTATION ); float h1 = VAL( BASE_LENGTH ); float h2 = VAL( LOWER_LENGTH ); float h3 = VAL( UPPER_LENGTH ); float pc = VAL( PARTICLE_COUNT ); // This call takes care of a lot of the nasty projection // matrix stuff ModelerView::draw(); static GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 }; Mat4f temp = getModelViewMatrix(); // define the model ground(-0.2); if (true) { Ariou(); } else { base(0.8); glTranslatef( 0.0, 0.8, 0.0 ); // move to the top of the base glRotatef( theta, 0.0, 1.0, 0.0 ); // turn the whole assembly around the y-axis. rotation_base(h1); // draw the rotation base glTranslatef( 0.0, h1, 0.0 ); // move to the top of the base glRotatef( phi, 0.0, 0.0, 1.0 ); // rotate around the z-axis for the lower arm glTranslatef( -0.1, 0.0, 0.4 ); lower_arm(h2); // draw the lower arm glTranslatef( 0.0, h2, 0.0 ); // move to the top of the lower arm glRotatef( psi, 0.0, 0.0, 1.0 ); // rotate around z-axis for the upper arm upper_arm(h3); // draw the upper arm glTranslatef( 0.0, h3, 0.0 ); glRotatef(cr, 0.0, 0.0, 1.0); claw(1.0); SpawnParticles(temp); } //*** DON'T FORGET TO PUT THIS IN YOUR OWN CODE **/ endDraw(); }
// We are going to override (is that the right word?) the draw() // method of ModelerView to draw out RobotArm void RobotArm::draw() { /* pick up the slider values */ float theta = baseRotation.getValue(); float phi = lowerTilt.getValue(); float psi = upperTilt.getValue(); float cr = clawRotation.getValue(); float h1 = baseLength.getValue(); float h2 = lowerLength.getValue(); float h3 = upperLength.getValue(); static GLfloat lmodel_ambient[] = {0.4,0.4,0.4,1.0}; // define the model ground(-0.2); base(0.8); glTranslatef( 0.0, 0.8, 0.0 ); // move to the top of the base glRotatef( theta, 0.0, 1.0, 0.0 ); // turn the whole assembly around the y-axis. rotation_base(h1); // draw the rotation base glTranslatef( 0.0, h1, 0.0 ); // move to the top of the base glRotatef( phi, 0.0, 0.0, 1.0 ); // rotate around the z-axis for the lower arm glTranslatef( -0.1, 0.0, 0.4 ); lower_arm(h2); // draw the lower arm glTranslatef( 0.0, h2, 0.0 ); // move to the top of the lower arm glRotatef( psi, 0.0, 0.0, 1.0 ); // rotate around z-axis for the upper arm upper_arm(h3); // draw the upper arm glTranslatef( 0.0, h3, 0.0 ); glRotatef( cr, 0.0, 0.0, 1.0 ); claw(1.0); }
int main() { struct cbcRobot robot = {0,3,150,55,1100}; //Define the robot. 0 and 3 are the motor ports, //150 mm is the wheel distance //55 is wheel diameter, 1100 is ticks per rotation light_it_up(4); //Wait for the light to turn on set_servo_position(arm_servo, top_pos); //Set the arm servo to the top position shut_down_in(118.0); //Shut down in 118 seconds //msleep(5000); //Wait 5 seconds float initial_time=seconds(); //Create a variable that records the initial time cbc_align(400); //Align with both of the top hats on the black line ao(); cbc_align_white(300); lower_arm(600); //Lower claw and open arm open_claw(600); cbc_straight(140, 800); //Straight out to get away from pvc wait_for_cbc(); cbc_arc_left(160, 135, 100); //Get past pvc to lower arm and open claw wait_for_cbc(); cbc_straight(180, 800); //Go straight into tribbles wait_for_cbc(); close_claw(1000); //Close claw on tribbles cbc_straight(280, 800); wait_for_cbc(); raise_arm(1200); //Raise the arm msleep(800); cbc_arc_right(180, 34, 80); //Arc right to get into position to approach the lattice wall wait_for_cbc(); cbc_touch(700, 5000); //Bump into lattice wall msleep(300); cbc_straight(-100, 600); //Back up 10 cm from wall wait_for_cbc(); open_claw(800); //Open claw to release tribbles and turn 94 degrees right cbc_spin(-94, 500); wait_for_cbc(); cbc_straight(120, 700); //Go forward into the turnstile and lower arm to mid position arm_mid(2000); msleep(1200); cbc_spin(20, 500); //Turn 20 degrees left to hit the turnstile out of the way wait_for_cbc(); msleep(200); cbc_spin(-16, 700); //Turn back 16 degrees to the right and close the claw close_claw(800); wait_for_cbc(); cbc_straight(-280, 800); //Go backwards to get into position to grab the tribbles wait_for_cbc(); lower_arm(1000); //Lower the arm and open the claw msleep(800); open_claw(800); msleep(1000); cbc_spin(8,700); //Turn 8 degrees to get ready to grab the tribbles wait_for_cbc(); cbc_arc_left(1500, 6, 100); //Go nearly straight into the tribbles wait_for_cbc(); close_claw(200); //Go forward and grab the tribbles cbc_straight(200, 600); wait_for_cbc(); close_claw(600); msleep(800); cbc_straight(-60, 600); //Back up to clear the turnstile raise_arm(1000); wait_for_cbc(); cbc_spin(4,700); //Turn slightly left wait_for_cbc(); follow_tape_left(600); //Run into the turnstile for horizonal alignment cbc_straight(-100, 400); //Back up before crossing over to the other side wait_for_cbc(); cbc_spin(90, 500); //Turn 90 degrees to the left wait_for_cbc(); cbc_straight(-80, 600); //Back up and align with the black tape wait_for_cbc(); cbc_align(400); ao(); cbc_straight(-50, 300); //Back up and align with the black tape wait_for_cbc(); cbc_align(400); ao(); cbc_straight(540,800); //Go forward to the other side wait_for_cbc(); open_claw(1000); //Open the claw to release tribbles and arc right approximately 100 degrees mrp(robot.leftWheel,780,2340); mrp(robot.rightWheel,400,1200); bmd(robot.leftWheel); bmd(robot.rightWheel); msleep(200L); lower_arm(1400);//Go forward and lower the arm msleep(500L); cbc_straight(370, 800); wait_for_cbc(); close_claw(1000); //Go forward and close the claw cbc_straight(300,800); wait_for_cbc(); raise_arm(1500); //Raise the arm msleep(800); cbc_spin(-73,500); //Turn 73 degrees right wait_for_cbc(); open_claw(1000); //Run into the lattice wall and open the claw to release the tribbles cbc_touch(500, 5000); cbc_straight(-80, 600); //Back up 8 cm from wall wait_for_cbc(); cbc_spin(-92, 500); //Turn 92 degrees right and close the claw close_claw(1000); wait_for_cbc(); cbc_straight(-80, 600); //Go backwards to get into position to grab the tribbles wait_for_cbc(); lower_arm(1500); //Lower the arm and open the claw msleep(800); open_claw(800); msleep(1000); cbc_spin(4,700); //Turn a bit in order to put the robot in an optimal tribble gathering position wait_for_cbc(); cbc_arc_left(1500, 6, 100); //Go nearly straight into the tribbles wait_for_cbc(); close_claw(200); //Go forward and grab tribbles cbc_straight(180, 600); wait_for_cbc(); close_claw(600); msleep(800); cbc_straight(-80, 400); //Back up to clear the turnstile wait_for_cbc(); raise_arm(1200); //Raise the arm msleep(500); cbc_straight(220, 700); //Go forward into the turnstile wait_for_cbc(); cbc_spin(80, 500); //Turn 80 degrees to the left wait_for_cbc(); cbc_straight(-80, 600); //Back up and align with the black tape wait_for_cbc(); cbc_align(400); ao(); cbc_straight(-50, 300); //Back up and align with the black tape wait_for_cbc(); cbc_align(400); ao(); //cbc_straight(1080, 800); //Old go forward function //wait_for_cbc(); mrp(robot.rightWheel,825,7700); //Go forward and correct the non-straightness of the motors mrp(robot.leftWheel,800,7700); wait_for_cbc(); cbc_touch(500, 5000); //Run into the wall msleep(300); cbc_straight(-125, 600); //Back up 12.5 cm from wall wait_for_cbc(); cbc_spin(90, 500); //Turn 90 degrees to the left wait_for_cbc(); while(analog10(et_right)<850) //While the tape is not seen by the right top hat { mav(robot.rightWheel,615); //Go forward mav(robot.leftWheel,600); msleep(25L); } off(robot.rightWheel); //Turn the motors off off(robot.leftWheel); cbc_straight(240, 700); //Go forward to get under the injection chute wait_for_cbc(); msleep(8000); //Wait for the injection chute tribbles to be loaded up cbc_straight(250, 700); //Go forward into the wall wait_for_cbc(); cbc_straight(-40, 600); //Back up 4 cm from pvc wait_for_cbc(); arm_mid(1000); //Lower the arm to the mid position and open the claw msleep(800); open_claw(800); msleep(800); cbc_straight(-40, 600); //Back up 4 cm from pvc wait_for_cbc(); close_claw(1000); //Turn around 180 degrees and close the claw cbc_spin(180,600); wait_for_cbc(); cbc_straight(-80, 480); //Back up to wall wait_for_cbc(); lower_arm(1400); //Lower the arm msleep(800L); mrp(dump_mot, 200, 500); //Dump the tribble into the MPA bmd(dump_mot); msleep(1000); mrp(dump_mot, 200, -500); //Dump the tribble into the MPA bmd(dump_mot); mrp(dump_mot, 200, 500); //Dump the tribble into the MPA bmd(dump_mot); mrp(dump_mot, 200, -500); //Dump the tribble into the MPA bmd(dump_mot); float time = seconds() - initial_time; //Create a variable that represents the time taken for the robot to complete its program cbc_display_clear(); //Clear the CBC display and then print the time the robot took to complete its program printf("Time: %f",time); return 0; }