Пример #1
0
int find_item()
{
	camera_update();
	point2 mcenter = get_object_center(1,0);
	set_servo_position (0 ,400);
	while(get_object_count(1) == 0){
		camera_update();
		create_spin_CCW(25);
	}
	create_stop();
	sleep(1);
	create_spin_CW(15);
	msleep(100);
	while(mcenter.x < 70 || mcenter.x > 100){
		camera_update();
		mcenter = get_object_center(1,0);
		if(mcenter.x < 70){
			create_spin_CCW(15);
			camera_update();
			mcenter = get_object_center(1,0);
		}
		if(mcenter.x < 100){
			create_spin_CW(15);
			camera_update();
			mcenter = get_object_center(1,0);
		}
		if(mcenter.x > 70 && mcenter.x < 100){
			create_stop();
		}
	}
	beep();
	
}
Пример #2
0
static void right(int angle, float radius, int speed) {
    if(radius < 0.)
        return;
    if (speed < -500 || speed > 500)
        return;
    if(angle < 0.) {
        create.left(-angle, radius, speed);
        return;
    }

    long radiusTicks = radius * CTICK_PER_CM;
    create.set_total_angle(0);

    if(radius == 0)
        create_spin_CW(speed);
    else {
        // create turn byte (decimal): 137
        // [137][speed high][speed low][radius high][radius low]
        create.write_byte(137);
        create.write_int(speed);
        create.write_int(-radiusTicks);
    }

    while(create.get_total_angle() >= -angle);

    create.block();
}
Пример #3
0
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
}
Пример #4
0
	void TurnCW()
	{
		while(get_create_total_angle(0.1) > -90)
		{
			create_spin_CW(500);
		}
		create_stop();
	}
Пример #5
0
/*
 * Class:     cbccore_low_Create
 * Method:    create_spin_CW
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_cbccore_low_Create_create_1spin_1CW(JNIEnv *env, jobject obj, jint speed)
{
#ifdef CBC
    create_spin_CW(speed);
#else
    printf("Java_cbccore_low_Create_create_1spin_1CW stub\n");
#endif
}
Пример #6
0
void turn_for(int angle, int speed) {

  set_create_total_angle(0);

  if (speed > 0) {
    while (get_create_total_angle() >-angle) {
      create_spin_CW(speed);
    }
    create_spin_CW(0);
  }

  else if (speed < 0) {

    while (get_create_total_angle() < angle) {
      create_spin_CW(speed);
    }

    create_spin_CW(0);
  } 

}
/*Function definitions go below.*/
void CenterCamera2() //CAMERA MUST BE AT CENTER OF CREATE, POINTING Right RESPECT TO CREATE
{
	if (track_x(0,0) > 81)			//if blocks are bd
	{
		for(create_spin_CCW(100); track_x(0,0) > 81; track_update()){}	//WHAT TRACK # IS RED? MAKE SURE IT DOESNT DETECT BOTGUY -- remember to calibrate CBC to  blocks
		create_stop();
	}
	if (track_x(0,0) < 78)			//if blocks are fd
	{
		for(create_spin_CW(100); track_x(0,0) < 78; track_update()){}	//WHAT TRACK # IS RED? MAKE SURE IT DOESNT DETECT BOTGUY -- remember to calibrate CBC to  blocks
		create_stop();
	}
}
Пример #8
0
// script to rotate in place through deg degrees
// deg > 0 turn CCW; deg < 0 turn CW
void create_script_turn(int deg, int speed) { // degrees, vel in mm/sec
    int sangle, dangle;
    create_angle();
    sangle=gc_total_angle;
    dangle=sangle+deg;
    if(deg>0){
        create_spin_CCW(speed);
        while(gc_total_angle<dangle)create_angle();
    }
    else{
        create_spin_CW(speed);
        while(gc_total_angle>dangle)create_angle();
    }
    create_stop();
}
Пример #9
0
//generic right angle turn in place
void rightAngle (int direction){
	
	if (direction == RIGHT) { 
		//then well turn 90 deg to the RIGHT
		create_spin_CW(100);
		msleep(RIGHT_ANG_RIGHT);
	} else if (direction == LEFT) {
		//then well turn 90 deg to the LEFT
		create_spin_CCW(100);
		msleep(RIGHT_ANG_LEFT);
	} else {
		printf("sorry I don't understand what you want me to do... ignoring right angle turn command\n");
	}
	create_stop();
}
Пример #10
0
void turn_while(float s , float a , int d)
{
	a *= DEG_TO_RAD;
	float t = ((RADIUS * a) / s);
	if (d == 1)
	{
		create_spin_CCW((int)s);
		msleep((int)(t * 1000));
		
	}
	if (d == -1)
	{
		create_spin_CW((int)s);
		msleep((int)(t * 1000));
	}
}
Пример #11
0
void clearWall()
{
	if(TOUCH_BACK_AND)		driveAtMmFor(-50,1);
	else if(TOUCH_FRONT)	driveAtMmFor(50,1);
	else if(TOUCH_BACK_OR){
		if(TOUCH_BACK_LEFT){
			create_spin_CW(50);
			while(!TOUCH_BACK_RIGHT){}
			create_stop();
		}
		if(TOUCH_BACK_RIGHT){
			create_spin_CCW(50);
			while(!TOUCH_BACK_LEFT){}
			create_stop();
		}
	}
}
Пример #12
0
void TurnCW()
{
	#ifdef CREATE
	while(get_create_total_angle(0.1) > -90)
	{
		create_spin_CW(500);
	}
	create_stop();
	#endif
	#ifdef CBC
	mav(1,500);
	mav(0,-500);
	sleep(2.5900127);
	off(0);
	off(1);
	#endif
	}
Пример #13
0
int main()
{
	create_connect();
	float x=.45;
	if(black_button() == 1)
	{
		create_drive_straight(-100);
		sleep(10);
		create_stop();
	}
	while(left_button() == 0) 
	{
		while(black_button() == 0)
		{
			if (a_button() == 1)
			{
				x=x+.001;
				printf("%f\n", x);
				sleep(.5);
			}
			if (b_button() == 1)
			{
				x=x-.001;
				printf("%f\n", x);
				sleep(.5);
			}
			if (up_button() == 1)
			{
				x=x+.0001;
				printf("%f\n", x);
				sleep(.5);
			}
			if (down_button() == 1)
			{
				x=x-.0001;
				printf("%f\n", x);
				sleep(.5);
			}
		}
		create_spin_CW(450);
		sleep(x);
		create_stop();
	}
}
Пример #14
0
int main(int argc, char ** argv)
{
	int i;

	printf("Connecting...\n");
	create_connect();

	create_start();

	printf("Spinning CW...n");
	create_spin_CW(40);

	// spin a while CW
	for (i = 0; i < 10; ++i)
	{
		printf("Distance: %d  Angle: %d\n", get_create_distance(), get_create_total_angle());
		msleep(1000);
	}

	printf("Spinning CCW...n");
	create_spin_CCW(40);

	// spin a while CCW
	for (i = 0; i < 10; ++i)
	{
		printf("Distance: %d  Angle: %d\n", get_create_distance(), get_create_total_angle());
		msleep(1000);
	}


	printf("Stopping...\n");
	create_stop();

	printf("Disconnecting...\n");
	create_disconnect();

	printf("Done.\n");

	return 0;
}
Пример #15
0
void CenterCamera() //CAMERA MUST BE AT CENTER OF CREATE, POINTING Right RESPECT TO CREATE
{
	track_update();
	if (track_x (0,0) > 81)
	{
		create_drive_straight(-200);
		while (track_x (0,0) > 81)	//WHAT TRACK # IS RED? MAKE SURE IT DOESNT DETECT BOTGUY
		{
			track_update();
		}
		create_stop();
		drivemm(inchestomm(4.9), 1);
		set_create_total_angle(0);
		create_drive(101.3,1);  //uses int. does it round?
		sleep(2.057252314);
		create_stop();
		get_create_total_angle(.1);
		printf("asdb");
		if (get_create_total_angle(.1) != 90)
		{
			set_create_total_angle(get_create_total_angle(.1) - 90);
			printf("%f\n",get_create_total_angle(.1));
			if (get_create_total_angle(.1) > 0) //CCW ADDS TO TOTAL ANGLE
			{
				create_spin_CW(100);
				while (get_create_total_angle(.1) < 0);
				{
					printf("aeqweqw");
				}
				create_stop();
			}
			if (get_create_total_angle(.1) < 0)
			{
				create_spin_CCW(100);
				while (get_create_total_angle(.1) > 0);
				{
					printf("BBBB");
				}
				create_stop();
			}
		}
	}
	/* (track_x (0,0) < 79)
	{
	create_drive_straight(200);
	while (track_x (0,0) < 79)
	{
	track_update();
	}
	create_stop();
	beep();
	set_create_distance(0);
	drivemm(-inchestomm(5), 1);
	create_drive(206.972051,1);
	sleep(1);
	create_stop();
	create_drive_straight(-200);
	while(digital(8 == 0))
	{
	}
	create_stop();
	}*/
}
Пример #16
0
int main()
{
	int stupid_int = 0;	
	int value = 0;
	int i = 0;
	int angle_of_pole = 90;
	camera_open(LOW_RES);
	camera_update();
	create_connect();	

	
	set_create_total_angle(0);
	value = get_create_total_angle();
	printf("Angle is %d\n", value);
	//------------------------
// part 1: spin until past all booster sections
	
	while(get_create_total_angle() > -85){
		create_spin_CW(75);
	}
	
	//---------------------
	//end part 1
	camera_update();
	sleep(2);
	point2 mcenter = get_object_center(1,0);
	set_servo_position(0,OPEN_POSITION); //this is opening the claw so it won't go to a random position when enabling the servos
	enable_servos();
//--------------------------------------
// part 2: find booster section using function i wrote at bottom of code then line up with B2(pole)
	
	find_item();
	printf("I saw a booster section!\n");
	while(digital(10) == 0) {	
		create_drive_straight(-50);
		if(digital(10) == 1){
			create_stop();
		}
	}
		
		while(stupid_int == 0) {
			if (digital(10) == 1){
					set_servo_position(0,CLOSE_POSITION_FOR_BOOSTER_SECTIONS);	
					stupid_int == 1;
					msleep(200);
				printf("I have grabbed a booster section!\n");
			}
		}
		move_to_position(0, -900, UPPOSITION);
		set_create_total_angle(0);
	while(get_create_total_angle() < angle_of_pole){
		create_spin_CCW(75);
	}
	
	//---------------------
	//end part 2
	
	set_create_total_angle(0);
// part 3: go forward until i find B2 (not complete)
	
	set_servo_position(1,OPEN_POSITION); 
	angle_of_pole = 60;
//end part 3
	
	//part 4: repeat everything
	/*while(get_create_total_angle() > -80){
		create_spin_CW(75);
	}
	
	//---------------------
	//end part 1
	camera_update();
	sleep(2);
	point2 mcenter = get_object_center(0,0);
	set_servo_position(0,OPEN_POSITION); //this is opening the claw so it won't go to a random position when enabling the servos
//--------------------------------------
// part 2: find booster section using function i wrote at bottom of code then line up with B2(pole)
	
	find_item();
	printf("I saw a booster section!\n");
	while(digital(10) == 0) {	
		create_drive_straight(-50);
		if(digital(10) == 1){
			create_stop();
		}
	}
		
		while(stupid_int == 0) {
			if (digital(10) == 1){
					set_servo_position(0,CLOSE_POSITION_FOR_BOOSTER_SECTIONS);	
					stupid_int == 1;
					msleep(200);
				printf("I have grabbed a booster section!\n");
			}
		}
		move_to_position(0, -900, UPPOSITION);
		set_create_total_angle(0);
	while(get_create_total_angle() < angle_of_pole){
		create_spin_CCW(75);
	}
	
	//---------------------
	//end part 2
	
	set_create_total_angle(0);
// part 3: go forward until i find B2 (not complete)
	
	set_servo_position(1,OPEN_POSITION); 
	angle_of pole = 50;
//end part 3
	while(get_create_total_angle() > -70){
		create_spin_CW(75);
	}
	
	//---------------------
	//end part 1
	camera_update();
	sleep(2);
	point2 mcenter = get_object_center(0,0);
	set_servo_position(0,OPEN_POSITION); //this is opening the claw so it won't go to a random position when enabling the servos
//--------------------------------------
// part 2: find booster section using function i wrote at bottom of code then line up with B2(pole)
	
	find_item();
	printf("I saw a booster section!\n");
	while(digital(10) == 0) {	
		create_drive_straight(-50);
		if(digital(10) == 1){
			create_stop();
		}
	}
		
		while(stupid_int == 0) {
			if (digital(10) == 1){
					set_servo_position(0,CLOSE_POSITION_FOR_BOOSTER_SECTIONS);	
					stupid_int == 1;
					msleep(200);
				printf("I have grabbed a booster section!\n");
			}
		}
		move_to_position(0, -900, UPPOSITION);
		set_create_total_angle(0);
	while(get_create_total_angle() < angle_of_pole){
		create_spin_CCW(75);
	}
	
	//---------------------
	//end part 2
	
	set_create_total_angle(0);
// part 3: go forward until i find B2 (not complete)
	
	set_servo_position(1,OPEN_POSITION); 
	angle_of pole = 50;
//end part 3
	while(get_create_total_angle() > -100){
		create_spin_CW(75);
	}
	
	//---------------------
	//end part 1
	camera_update();
	sleep(2);
	point2 mcenter = get_object_center(0,0);
	set_servo_position(0,OPEN_POSITION); //this is opening the claw so it won't go to a random position when enabling the servos
//--------------------------------------
// part 2: find booster section using function i wrote at bottom of code then line up with B2(pole)
	
	find_item();
	printf("I saw a booster section!\n");
	while(digital(10) == 0) {	
		create_drive_straight(-50);
		if(digital(10) == 1){
			create_stop();
		}
	}
		
		while(stupid_int == 0) {
			if (digital(10) == 1){
					set_servo_position(0,CLOSE_POSITION_FOR_BOOSTER_SECTIONS);	
					stupid_int == 1;
					msleep(200);
				printf("I have grabbed a booster section!\n");
			}
		}
		move_to_position(0, -900, UPPOSITION);
		set_create_total_angle(0);
	while(get_create_total_angle() < angle_of_pole){
		create_spin_CCW(75);
	}
	
	//---------------------
	//end part 2
	
	set_create_total_angle(0);
// part 3: go forward until i find B2 (not complete)
	
	set_servo_position(1,OPEN_POSITION); 
	angle_of pole = 40;
//end part 3
	while(get_create_total_angle() > -60){
		create_spin_CW(75);
	}
	
	//---------------------
	//end part 1
	camera_update();
	sleep(2);
	point2 mcenter = get_object_center(0,0);
	set_servo_position(0,OPEN_POSITION); //this is opening the claw so it won't go to a random position when enabling the servos
//--------------------------------------
// part 2: find booster section using function i wrote at bottom of code then line up with B2(pole)
	
	find_item();
	printf("I saw a booster section!\n");
	while(digital(10) == 0) {	
		create_drive_straight(-50);
		if(digital(10) == 1){
			create_stop();
		}
	}
		
		while(stupid_int == 0) {
			if (digital(10) == 1){
					set_servo_position(0,CLOSE_POSITION_FOR_BOOSTER_SECTIONS);	
					stupid_int == 1;
					msleep(200);
				printf("I have grabbed a booster section!\n");
			}
		}
		move_to_position(0, -900, UPPOSITION);
		set_create_total_angle(0);
	while(get_create_total_angle() < angle_of_pole){
		create_spin_CCW(75);
	}
	
	//---------------------
	//end part 2
	
	set_create_total_angle(0);
// part 3: go forward until i find B2 (not complete)
	
	set_servo_position(1,OPEN_POSITION); 
	angle_of pole = 60;
//end part 3*/
//end part 4
}
int turnr(x)
{
	create_spin_CW(x);
}
Пример #18
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;
}
Пример #19
0
//main stuff haha
int main()
{
  int claw = 1;     //claw port
  int arm = 0;      //arm port
  create_connect();  
  printf("create connected"); 
  set_create_total_angle(0);
  //create setup

  turn_for(10, -200); //Turns the create around
  
  //does some important stuff
  create_drive_direct(-100, -100);
  set_servo_position(claw, 1561);
  enable_servos();
  msleep(300);

  set_servo_position(arm, 1850); //arm down
  msleep(500);
  set_servo_position(claw, 1000);
  msleep(500);
  set_servo_position(arm, 1643); //grabs ball
  msleep(500);

  turn_for(36, 200); //spins onto first black path to line follow later
  msleep(500);

  forward_for(50, -100); //moves forward onto the black line

  line_follow(blackThresh , 212); //starts following the black line
  set_servo_position(claw, 1561); //drops ball
  //dropped ball already
  msleep(400);

  forward_for(500, 100); //back it up back it up

  set_servo_position(arm, 245); //holds the arm up
  msleep(100);
  set_create_distance(0);
  set_create_total_angle(0);

  while (get_create_total_angle() > -10) { //spins itself onto the angle of other black line
    create_spin_CW(200);
  }

  create_spin_CW(0); //stops spinning
  msleep(1500);

  create_drive_direct(-200, -200); //goes onto the black line to line follow later
  msleep(1000);

  create_drive_direct(0,0); //stops itself
  msleep(500);

  set_create_total_angle(0);
  while (get_create_total_angle() > -3) { //angles itself a little bit
    create_spin_CW(200);
  }
  create_spin_CW(0); //stops spinning
  msleep(400);

  create_drive_direct(-200, -200); //Drives forward a little bit to the next black line
  msleep(1500);
  create_drive_direct(0,0);

 set_create_total_angle(0);
  while (get_create_total_angle() > -7) { //Angles itself so it can drive in the middle
    create_spin_CW(200);
  }

  create_spin_CW(0); //stops spinning

  create_drive_direct(-230,-230); //Drives itself into the middle lane
  msleep(4000);

  create_drive_direct(0,0); //Reset stuff
  set_create_total_angle(0);

  while(analog(0) < blackThresh) { //Align itself using line following in the middle lane
     create_spin_CW(50);
     printf("Value is %d \n", analog(0));

     if(digital(0) >= blackThresh) {
      printf("I have found the middle black line!");
      create_spin_CW(1); //Angle itself so it is exactly on the black line
     }
  }

  create_spin_CW(0); //resets something for some reason why is this here?


  set_servo_position(claw, 1561); //grabs the red cube
  msleep(200);
  set_servo_position(arm, 1984);
  msleep(500);
  set_servo_position(claw, 1144);
  msleep(500);

  return 0;
}
Пример #20
0
wiggleCreateRight() {
	create_spin_CW(300);
	sleep(.15);
	create_stop();
}