Пример #1
0
//routine to use the camera and see blob position based on standard create start routine
void calibrateCamera() {
	int channel = 0;
	while (a_button_clicked() == 0) {
		msleep(2000);
		camera_update();
		printf ("=> object count %d \n", get_object_count(channel));
		int i = 0; 
		int shelfPlaces[8] = {0,0,0,0,0,0,0,0};
		while (i < get_object_count(channel)) {
			printf("obj %d, ctr loc, area, shelf plcmt: %d, %d, %d\n", i, get_object_center(channel, i).x, get_object_area(channel, i), 
			getShelfPlacement(get_object_center(channel, i).x));
			shelfPlaces[getShelfPlacement(get_object_center(channel, i).x)] += get_object_area(channel, i);
			i++;
		}
		printf("==========================\n");
		printf("=RESULTS                 =\n");
		printf("==========================\n");
		i = 1; 
		while (i < 8) {
			printf ("shelfPlace : %d, total cube area : %d\n", i, shelfPlaces[i]);
			i++;
		}
		printf("==========================\n");
		printf("click b button for new camera capture, a to exit.\n");
		while (b_button_clicked() == 0 && a_button_clicked() == 0 )  {
			msleep(25); 
		}
	}
	printf("done with calibration function.\n");
	
}
Пример #2
0
int main()
{
	
	printf("Hello, World!\n");
	set_a_button_text("Some button a");
	set_b_button_text("That other button");
	set_c_button_text("Useless button");
	create_connect();
	printf("The buttons have been renamed.\n Deal with it.\n Press button 'some button' &\n 'That other button' for beeps.\n 'Useless button' stops the beeps.\n");
	while (side_button() ==0){
		if (a_button() == 1){// can hold for continuous beeps
			printf("beep\n");
			beep();
			msleep(500);
		}
		else if (b_button_clicked() == 1){// must release button
			printf("beep-beep\n");
			beep();
			msleep(300);
			beep();
		}
		else {
			printf("No button pressed.\n");
		}
	}
		printf("I quit");
	create_disconnect();
	return 0;
}
Пример #3
0
int main()
{
	while (b_button_clicked() == 0);
	while (a_button() == 0)
	{
		t_line_follow();
		printf("%d , %d , %d\n" , get_left() , get_middle() , get_right());
	}
	return 0;
}
int getFirstButtonPressed(){ //returns 0 for A, 1 for B, 2 for C.
	while(1==1){
		if(a_button_clicked()==1){
			return 0;
		}
		if(b_button_clicked()==1){
			return 1;
		}
		if(c_button_clicked()==1){
			return 2;
		}
		msleep(40);
	}
}
Пример #5
0
int main()
{
	int m1=0,m2=3,pageno=0;
	double createDriveTime;
	printf("Start!\n");
	extra_buttons_show();
	while (1)
	{
		while (pageno == 0)
		{
			set_a_button_text("Forward");
			set_b_button_text("Backward");
			set_c_button_text("All Off");
			set_x_button_text("OpenHand");
			set_y_button_text("CloseHand");
			set_z_button_text("Create Page");
			
			if (a_button_clicked())
			{
				printf("Moving forward...\n");
				motor(m1,100);
				motor(m2,100);
				while (!c_button_clicked())
				{
					msleep(1);
				}
				ao();
			}
			if (b_button_clicked())
			{
				printf("Moving backward...\n");
				motor(m1,-100);
				motor(m2,-100);
				while (!c_button_clicked())
				{
					msleep(1);
				}
				ao();
			}
			if (x_button_clicked())
			{
				enable_servo(3);
				set_servo_position(3,0);
				msleep(300);
				disable_servo(3);
			}
			if (y_button_clicked())
			{
				enable_servo(3);
				set_servo_position(3,1300);
				msleep(300);
				disable_servo(3);
			}
			if (z_button_clicked())
			{
				pageno=1;
				create_connect();
			}
		}

		while (pageno == 1)
		{
			set_a_button_text("Create Fwd");
			set_b_button_text("Create Bwd");
			set_c_button_text("Stop");
			set_x_button_text("Turn R");
			set_y_button_text("Turn L");
			set_z_button_text("M S Page");
			
			if (a_button_clicked())
			{
				createDriveTime = 0;
				printf("Create Moving forward w/ spd 100...\n");
				create_drive_straight(100);
				createDriveTime = seconds();
				while (!c_button_clicked())
				{
					msleep(1);
				}
				create_stop();
				printf("Time: %f seconds\n",seconds() - createDriveTime );
			}
			if (b_button_clicked())
			{
				createDriveTime = 0;
				printf("Create Moving backward w/ spd 100...\n");
				create_drive_straight(-100);
				createDriveTime = seconds();
				while (!c_button_clicked())
				{
					msleep(1);
				}
				create_stop();
				printf("Time: %f seconds\n",seconds() - createDriveTime );
			}
			if (x_button_clicked())
			{
				create_drive(-50,0);
				while (!c_button_clicked())
				{
					msleep(1);
				}
				create_stop();
			}
			if (y_button_clicked())
			{
				create_drive(50,0);
				while (!c_button_clicked())
				{
					msleep(1);
				}
				create_stop();
			}
			if (z_button_clicked())
			{
				pageno=0;
				create_disconnect();
			}
		}
	}
	
	return 0;
}
Пример #6
0
void wait_for_light(int light_port_)
{
	int xBut, l_on_, l_off_, l_mid_, t, OK = 0;
	float s;
	xBut = get_extra_buttons_visible();
	set_extra_buttons_visible(0);
	set_a_button_text("-");
	set_c_button_text("-");
	set_analog_pullup(light_port_, 1);
	while (!OK) {
		set_b_button_text("Light is On");
		display_clear();
		display_printf (0, 0, "CALIBRATE: sensor port #%d", light_port_);
		display_printf(0, 1, "   press button when light is on");
		while(b_button_clicked() == 0) {
			l_on_ = analog10 (light_port_);
			display_printf(0,1,"   light on value is = %d        ", l_on_);
			msleep(50);
		}
		l_on_ = analog10(light_port_); /* sensor value when light is on */

		set_b_button_text("Light is Off");

		display_printf(0,1,"   light on value is = %d        ", l_on_);
		msleep(200);
		beep();

		display_printf(0,2,"   press button when light off");
		while(b_button_clicked() == 0) {
			l_off_ = analog10(light_port_);
			display_printf(0,3,"   light off value is = %d         ", l_off_);
			msleep(50);
		}
		l_off_ = analog10(light_port_); /* sensor value when light is off */

		display_printf(0,3,"   light off value is = %d         ", l_off_);
		msleep(200);

		if((l_off_ - l_on_) >= 60) { /* bright = small values */
			OK = 1;
			l_mid_ = (l_on_ + l_off_) / 2;
			display_printf(0, 5, "Good Calibration!");
			display_printf(0, 7, "Diff = %d:  WAITING", l_off_ - l_on_);
			while(analog10(light_port_) > l_mid_);
		} else {
			s = seconds();
			display_printf(0,7,"BAD CALIBRATION");
			if(l_off_ < 512){
				display_printf(0,8,"   Add Shielding!!");
				msleep(5000);
			} else {
				display_printf(0,8,"   Aim sensor!!");
				msleep(5000);
			}
		}
	}
	set_extra_buttons_visible(xBut);
	set_a_button_text("A");
	set_b_button_text("B");
	set_c_button_text("C");
}