void drive_random()
{	
	srand ( time(NULL) );
	int direction=rand()%361-180;	//-180 to +180
	if(direction<0)
	{
		set_create_total_angle(0);
		create_drive_direct(-200,200);
		while(get_create_total_angle(0.1)>direction);
	}
	else
	{
		set_create_total_angle(0);
		create_drive_direct(200,-200);
		while(get_create_total_angle(0.1)<direction);
	}

	int i=0;
	while(i<1000)
	{
		if(get_create_lbump(0.1)||get_create_rbump(0.1))	//if bumper pressed
		{
			i=2000;
		}
		else
		{
			create_drive_direct(300,300);
		}
		i++;
		msleep(1);	
	}
	
	create_stop();
}
Exemple #2
0
void GotoBox()
{
	while (get_create_lbump(.1) == 0 && get_create_rbump(.1) == 0)//drive backwards until hit pvc w/ bumper
	{
		create_drive_straight(200); //unless arm is strong enough to hold
	}
	create_stop();
	ClearWall();	//move away from pvc to turn
	if(Side == 0)	//turn towards outer starting box -- now facing our outer starting box w/ blocks in claw
	{
		TurnCCW();
	}
	if(Side == 1)
	{
		TurnCW();
	}
	create_stop();
	ForwardTouch();	//forward till front touch sensor ==1
	create_drive_straight(132);  //one cube length (5 inches) + 5 mm safety // drive backwards
	sleep(1);
	Release();	// realease claw w/ 2 blocks -- block now in starting box
	create_drive_straight(-75);
	sleep(1);
	create_stop();  //make sure cubes are touching pvc
}
int main()
{	
  printf("Line Follow."); // announce the program	
  sleep(1.0); // wait 1 second

  create_connect(); // Open the connection between CBC and Create	
  int ana0 = 0, ana1 = 0; // variables to store the results of the analog sensors
	create_full(); // We don't care about safety
	while(get_create_lbump(0) == 0 && get_create_rbump(0) == 0){ //while the bumper is not pressed
		ana0 = analog10(0); // left sensor
		ana1 = analog10(1); // right sensor
		
		printf("analog 0: %d\n", ana0);// print results
		printf("analog 1: %d\n", ana1);
		if((ana0 < 200) && (ana1 > 200)) // if the left sensor is off and right is on black line
		{
			create_spin_CW(128); // spin the create Clock Wise
		}else if((ana1 < 200) && (ana0 > 200)) // else if reversed
		{
			create_spin_CCW(128); // spin Counter Clock Wise
		}else if((ana0 < 200) && (ana1 < 200)) // else neither is on the line
		{
			create_drive_straight(180); // drive straight
		}
		
	}
  create_stop(); // Stop the Create
  create_disconnect(); // Disconnect the Create
}
Exemple #4
0
/*
 * Class:     cbccore_low_Create
 * Method:    get_create_lbump
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_cbccore_low_Create_get_1create_1lbump(JNIEnv *env, jobject obj, jfloat lag)
{
#ifdef CBC
    return get_create_lbump(lag);
#else
    printf("Java_cbccore_low_Create_get_1create_1lbump stub\n");
    return 0;
#endif
}
Exemple #5
0
int main()
{
	printf("Tryying to connect to the Create\nBattery: %d...\n", get_create_battery_capacity());
	create_connect();
	printf("Connected...");
	while (get_create_lbump() == 0 && get_create_rbump() == 0)
	{
		create_drive_direct(150,150);
	}
	create_disconnect();
	printf("All done");
	return 0;
}
Exemple #6
0
void ClearWall()
{
	if(get_create_lbump(.1) == 1 || get_create_rbump(.1) == 1)
	{
		create_drive_straight(-132);  //one cube length (5 inches) + 5 mm safety
		sleep(1);
		create_stop();
	}
	if(digital(TouchSensor) == 1)
	{
		create_drive_straight(132);
		sleep(1);
		create_stop();
	}
}
Exemple #7
0
int main()
{
    printf("Hello Create\n");
    printf("press R button to start\n");
    while(digital(13) ==0) {
        msleep(20);
    }
    printf("Connecting\n");
    create_connect(); // this engages the create
    while(get_create_lbump()==0 && get_create_rbump()==0) {
        create_drive_direct(100,-100);
    }
    create_stop();
    create_disconnect();
    msleep(500);
    return 0;
}
Exemple #8
0
int main()
{
	printf("starting connor\n");
	enable_servo(1);
	set_servo_position(1,100);
	//disable_servo(1)
	create_connect(); 
	while (! digital(11))
	{
		printf("%d\n",  digital(11));
		create_drive_direct(-150,-150);
	}
	printf("starting connor\n");
	set_servo_position(1,1400);
	while (get_create_lbump() == 0 && get_create_rbump() == 0)
		{
		create_drive_direct(150, 150); // drive straight at 150mm/s
		}
	disable_servos();
}
int main() 
{
	printf("checklist");
	printf("hit black button when ready");
	while(black_button());
	printf("MAKE SURE CREATE IS ON!!!!!!!!");
	while(!black_button());
	printf("MAKE SURE ARM IS IN DOWN POSITION!!!!!!!!");
	while(!black_button());
	printf("MAKE SURE ARM AND CLAW WORK");
	while(!black_button());
	printf("CHECK POSITION OF CLAW AND ARM");
	while(!black_button());
	printf("MAKE SURE LIGHT SENSORT IS CALIBRATED");
	while(!black_button());
	// this starts the robot    SECTion 1
	wait_for_light(0);
	shut_down_in(120.0);
	//this shuts the robot down after 120.0 seconds
	while(create_connect());
	
		//connects create to cbc
	set_servo_position(3, 0);
	set_servo_position(0, 1800);
	enable_servos();
	msleep(500);
	create_full();
	//section 2
	create_drive_direct(SUPER_FAST, SUPER_FAST);
	msleep(1646);
	//leave beach
	create_stop();
	msleep(300);
	create_drive_direct(SUPER_FAST, -SUPER_FAST);
	msleep(435);
	//turn towards center
	create_stop();
	msleep(300);
	create_drive_direct(SUPER_FAST, SUPER_FAST);
	msleep(1600);
	//move towards botguy
	create_stop();
	msleep(500);
	//section 3
	set_servo_position(0, 1424);
	msleep(1800);
	set_servo_position(0, 1100);
	msleep(1800);
	set_servo_position(0, 924);
	msleep(1800);
	set_servo_position(0, 724);
	msleep(1800);
	set_servo_position(3, 1024);
	msleep(1800);
	set_servo_position(0, 924);
	msleep(1800);
	set_servo_position(0, 1100);
	msleep(1800);
	set_servo_position(0, 1200);
	msleep(2000);
	
	
	
	//retrieve botguy
	//section 4
	create_drive_direct(-FAST, FAST);
	msleep(445);
	create_stop();
	create_drive_direct(-FAST, -FAST);
	msleep(2000);
	create_stop();
	create_drive_direct(FAST, -FAST);
	msleep(445);
	create_stop();	
	create_drive_direct(-FAST, -FAST);
	msleep(900);
	create_stop();
	msleep(1600);
	create_stop();
	set_servo_position(3, 0);
	set_servo_position(0, 1800);
	msleep(1200);
	set_servo_position(0, 1200);
	msleep(1000);
	set_servo_position(0, 1800);
	msleep(1000);
	create_drive_direct(1000, 1000);
	msleep(800);
	create_drive_direct(-1000, -1000);
	msleep(800);
	DRIVE(SUPER_FAST);
	MSLEEP(800);
	TURN(-SUPER_FAST, SUPER_FAST);
	MSLEEP(460);
	DRIVE(SUPER_FAST);
	MSLEEP(1380);
	TURN(SUPER_FAST, -SUPER_FAST);
	MSLEEP(425);
	DRIVE(SUPER_FAST);
	SLEEP(1.5);
	while(get_create_lbump(0.01) == 0)
	{
		DRIVE(SUPER_FAST);
	}
	TURN(-SUPER_FAST, SUPER_FAST);
	MSLEEP(435);
	TURN(SUPER_FAST, 975);
	MSLEEP(500);
	while(get_create_rbump(0.01) == 0)
	{
		TURN(SUPER_FAST, 990);
	}
	
	
	
	create_stop();
	create_disconnect();
	
	
	
	
}
Exemple #10
0
void Cubes (void)
{
	if (Side == 0)
	{
		//Right of Botguy
		//keep offense in box until scorer gets into position
		//start with claw facing out
		ForwardTouch(); //until it hits luggage    DOES BAR TOUCH SENSOR REGISTER LUGGAGE TOUCH?
		TurnCCW();		//turn left -- now facing airplanes
		CenterCamera();	//move forwards and center the camera on the blocks -- now facing airplanes and in front of blocks
		TurnCCW();		//turn left to face blocks with claw -- now in front of and facing blocks
		ForwardTouch();	//move forward until it hits blocks
		Grab();			//grab blocks
		/*create_drive_straight(100);
		sleep(2);//to avoid crashing with our luggage carts
		create_stop();
		TurnCCW();*/
		//OFFENSE SHOULD BE OUT OF STARTING BOX BY NOW
		//FORWARD BAR SENSOR SHOULD NOT BE OBSTRUCTED
		//CREATE SHOULD DRIVE BACKWARDS
		GotoBox();
		create_drive_straight(200);
		sleep(1);
		create_stop();
		TurnCW();
		create_drive_straight(-300);
		sleep(1);
		create_stop();
		TurnCW();
		CenterCamera(); 
		TurnCCW();
		ForwardTouch();
		Grab();
		TurnCCW();
		create_drive_straight(-500);
		sleep(2.2352);
		TurnCW();
		GotoBox();
		Release();
	}
	if (Side == 1) //Left of Botguy. START WITH CREATE FACING OUT
	{
		ForwardTouch(); //Switch to distance
		TurnCW();
		ForwardTouch();
		create_drive_straight(50);
		sleep(1);
		create_stop();
		TurnCW();
		CenterCamera();
		TurnCCW();
		ForwardTouch();
		Grab();
		TurnCCW();
		/*create_drive_straight(100);
		sleep(1);
		create_stop();
		TurnCW();*/
		while (get_create_lbump(.1) == 0 && get_create_rbump(.1) == 0)
		{
			create_drive_straight(200); //unless arm is strong enough to hold
		}
		ClearWall();
		TurnCW();
		ForwardTouch();
		create_drive_straight(132);  //one cube length (5 inches) + 5 mm safety
		sleep(1);
		create_stop();
		create_drive_straight(-75);
		sleep(1);
		create_stop();
		Release();
		
	}
}
Exemple #11
0
int main(int argc, char** argv) {
    enable_servo(kServoPortSorter);
    set_servo_position(kServoPortSorter, kServoPositionSorterCenter);
    clear_motor_position_counter(kMotorPortBayLeft);
    clear_motor_position_counter(kMotorPortBayRight);
    create_connect();
    camera_open(LOW_RES);
    
    scanf("%s", NULL);
    printf("waiting for light\n");
    while (analog(0) > 200) {}
    
    shut_down_in(700000);
    
    motor(kMotorPortBayLeft, 10);
    motor(kMotorPortBayRight, 10);
    while (get_motor_position_counter(kMotorPortBayLeft) < 230 || get_motor_position_counter(kMotorPortBayRight) < 230) {
        printf("pos: %i/%i\n", get_motor_position_counter(kMotorPortBayLeft), get_motor_position_counter(kMotorPortBayRight));
    }
    motor(kMotorPortBayLeft, 0);
    motor(kMotorPortBayLeft, 0);
    // wait_for_side_button();
    
    msleep(6000);
    
    create_drive_straight(200);
    msleep(1850);
    create_spin_CCW(200);
    msleep(750);
    create_drive_straight(-200);
    msleep(1500);
    create_spin_CW(200);
    msleep(1750);
    create_drive_straight(200);
    while (!get_create_lbump() && !get_create_rbump()) {}
    create_drive_straight(-150);
    msleep(900);
    create_spin_CCW(200);
    msleep(950);
    create_drive_straight(150);
    while (!get_create_lbump() && !get_create_rbump()) {}
    create_stop();
    
    msleep(10000);
    
    thread all_off = thread_create(wait_for_kill);
    thread_start(all_off);
    
    raise_bay();
    create_spin_CW(100);
    msleep(500);
    create_drive_straight(-100);
    msleep(1000);
    create_stop();
    
    thread jiggle_c = thread_create(jiggle_create);
    thread_start(jiggle_c);
    thread sort_b = thread_create(sort_balls);
    thread_start(sort_b);
    
    msleep(33000);
    
    while (true) {}
    
    /*thread_destroy(jiggle_c);
    create_stop();
    lower_bay();
    create_drive_straight(100);
    while (!get_create_lbump() && !get_create_rbump()) {}
    create_stop();
    
    msleep(10000);
    
    raise_bay();
    create_spin_CW(100);
    msleep(500);
    create_drive_straight(-100);
    msleep(1000);
    create_stop();
    
    thread_create(jiggle_create);
    thread_start(jiggle_c);
    thread_create(sort_balls);
    
    while (true) {}
    
    camera_close();*/
    return 0;
}