Exemple #1
0
int send_message_to_agent(char* ip, int port, int type,  const char* buff, int len){
	int ret = create_connect(ip, port);
	if( ret == -1 ){
		perror("create connect failed");
		return -1;
	}
	printf("connect successfully!\n");
	int localip = update_pma_addr(ret);
	int pkt_len = sizeof( struct common_header) + len;
	void * newbuff = malloc(pkt_len);
	struct common_header* header = (struct common_header*)newbuff;
	header->pkg_type = type;
	header->pkg_version = 0x00;
	header->device_type = 0x00;
	header->pkg_len = htonl(pkt_len);

	memcpy(newbuff+ sizeof(struct common_header), buff, len);
	int status = send( ret, newbuff, pkt_len, 0);
	if( status == -1 )
	{
		perror( "send packet failed");
		return -1;
	}
	printf("Send packet success! PKT Type=%d Len=%d\n", type, len);
	close(ret);
}
/* This program will move Robot A accordig to its assignment. */
int main()
{
	printf("Hello, World!\n");
	create_connect();
	int rport=1; // identify ports used, might need to change
	int threshold=500; // light threshold in the room
	int high=100, low=-10; //motor power for arc. Will need to change to perfect drive. 
	while (b_button()==0) {} // start after pushing B 
	/* To be replaced with wait_for_light(port#); so that light starts the robot. Right now it is started with B*/
	while (a_button()==0){ // stop after pushing A
		/* to be relplaced with a button sensor. Such as digital(Port #); so that the claw grabs the transport when the sensor(s) are pushed.*/
			while (analog10(rport) > threshold) { // continue until not dark
			create_drive_direct(-10,100); // arc left
			if (a_button()!=0) break; } // or button pressed
			// to be replaced with a sensor
			while (analog10(rport) <= threshold){ // continue until dark
			create_drive_direct(100,-10); // arc right
			if (a_button()!=0) break; } // or button pressed 
			// to be replaced with a sensor
			create_stop();
			//all stop because button was pushed. 
		}
	create_disconnect();
	return 0;
}
Exemple #3
0
void Start() //Misc. set up functions
{
	create_connect();
	set_create_total_angle(0);
	//wait_for_light(LightPort);
	shut_down_in(RunTime); //TEST THIS	
}
Exemple #4
0
// if serial communication times out (ie., is lost), attempts to restart it
void create_reconnect()
{
	printf("Create communication lost;\nattempting reconnection.\n");
  create_disconnect();    // reset environment
	create_connect();

}
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
}
int main()
{
    X=0;
    create_connect();
    set_create_total_angle(0);
    printf("X\tAngle");
    while(black_button()==0)
    {
        if (a_button()==1)
        {
            turnHalfCCW();
            printf("%d\t%d\n",X,get_create_total_angle(0.1));
        }
        if (b_button()==1)
        {
            turnHalfCW();
            printf("%d\t%d\n",X,get_create_total_angle(0.1));
        }
        if (left_button()==1)
        {
            TurnCCW();
            printf("%d\t%d\n",X,get_create_total_angle(0.1));
        }
        if (right_button() == 1)
        {
            TurnCW();
            printf("%d\t%d\n",X,get_create_total_angle(0.1));
        }
    }
}
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;
}
int main()

{

    wait_for_light(4);

    printf("Hello, World!\n");

    create_connect();

    create_drive_direct(200 , 200);

    msleep(2000);

    create_spin_CCW ( 100 );

    msleep(2000);

    create_stop();

    create_drive_direct(200 , 200 );

    msleep(4000);

    create_stop();

    create_drive_direct (200 , 200);

    msleep(5000);

    create_stop();

    create_spin_CCW ( 100 );

    msleep(2000);

    create_drive_direct (200 , 200);

    msleep(3000);

    create_spin_CCW ( 100 );

    msleep(2000);

   

    create_cover();

    create_stop();

   

   

    create_disconnect();

    return 0;

}
Exemple #9
0
connect_client* connect_pool::peek()
{
	lock_.lock();
	if (alive_ == false)
	{
		time_t now = time(NULL);
		if (retry_inter_ <= 0 || now - last_dead_ < retry_inter_)
		{
			lock_.unlock();
			return NULL;
		}
		alive_ = true;

		// 重置服务端连接状态,以便重试
		logger("reset server: %s", get_addr());
	}

	connect_client* conn;

	std::list<connect_client*>::iterator it = pool_.begin();
	if (it != pool_.end())
	{
		conn = *it;
		pool_.erase(it);
		total_used_++;
		current_used_++;
		lock_.unlock();
		return conn;
	}
	else if (count_ >= max_)
	{
		logger_error("too many connections, max: %d, curr: %d,"
			" server: %s", (int) max_, (int) count_, addr_);
		lock_.unlock();
		return NULL;
	}

	// 调用虚函数的子类实现方法,创建新连接对象,并打开连接
	conn = create_connect();
	if (conn->open() == false)
	{
		delete conn;
		alive_ = false;
		(void) time(&last_dead_);
		lock_.unlock();
		return NULL;
	}

	count_++;

	total_used_++;
	current_used_++;

	lock_.unlock();

	conn->set_pool(this);

	return conn;
}
Exemple #10
0
void Start (void)
{
	wait_for_light(LightPort);
	shut_down_in (117); //TEST THIS
	create_connect();
	set_create_total_angle(0);
	
}
Exemple #11
0
int main()
{	
	create_connect();
	drive_distance(20, 35, FORWARDS);
	spin_degrees(90, 50, LEFT);
	drive_distance(14, 35, FORWARDS);
	create_disconnect();
}
int main()
{
	create_connect();
	init_servo();


	//light_it_up(LIGHT_PORT);
	lightstart(LIGHT_PORT,120.0);

	create_full();
	create_drive_segment(HIGH_SPEED, -150);
	start_process(set_top);
	create_drive_arc(HIGH_SPEED, -200, 155);
	create_drive_segment(HIGH_SPEED, -365);
	create_drive_arc(HIGH_SPEED, 90, -64);
	create_drive_segment(HIGH_SPEED, -85);
	create_cease();
	set_top();
	align_twall();
	grab_top_de();
	create_spin_angle(400,-165);
	create_drive_segment(HIGH_SPEED, -320);
	//align_wall();
	create_stop();
	create_sync();
	dump_kelp_de();
	create_drive_segment(HIGH_SPEED,30);//go away from starting box
	create_spin_angle(HIGH_SPEED, -78);//turn to gate part 1
	create_drive_segment(HIGH_SPEED, 938);//go to gate
	create_drive_arc(HIGH_SPEED,185,84);//arc to gate
	//create_drive_time(HIGH_SPEED,1800);//go through the gate
	/*
	create_drive_segment(HIGH_SPEED,1470);
	create_drive_segment(HIGH_SPEED,-100);
	create_spin_angle(HIGH_SPEED,78);
	*/
	create_cease();
	create_drive_straight(HIGH_SPEED);//go onto oppponent's side of board
	msleep(1400);
	create_stop();
	create_arc(350,550);//arc to the opponent's mpa
	msleep(2500L);
	create_stop();//pause to keep the creat
	create_drive_straight(HIGH_SPEED);//go onto oppponent's side of board
	msleep(750);
	create_stop();
	create_drive_straight(-HIGH_SPEED);//go onto oppponent's side of board
	msleep(5000);
	create_stop();
	/*
	create_drive_segment(500,-500);//go past the IC
	create_drive_arc(320,-250,25);//arc to
	create_drive_arc(320,250,-8);
	*/
	//create_drive_segment(HIGH_SPEED,-750);
	//create_drive_arc(HIGH_SPEED,100,84);
	//create_drive_segment(HIGH_SPEED,1300);
}
 /*
 * Class:     cbccore_low_Create
 * Method:    create_connect
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_cbccore_low_Create_create_1connect(JNIEnv *env, jobject obj)
{
#ifdef CBC
    return create_connect();
#else
   	printf("Java_cbccore_low_Create_create_1connect stub\n");
   	return -1;
#endif
}
Exemple #14
0
int main() {
	set_each_analog_state(0,1,0,0,0,0,0,0);
	create_connect();
	enable_servos();
	armPosSB();
	clawSB();
	//seedReturn();
	seed();
}
Exemple #15
0
int main()
{
	create_connect();
	create_full();
	while(digital(15) == 0);
	create_drive_direct(-1500, -1500);
	while(!(a_button_clicked()));
	return 0;
}
Exemple #16
0
int main()
{
	get_mode();
	create_connect();
	drop_three_hangers();
	pick_up_first_doubler();
	create_disconnect();
	return 0;
}
 uint32_t create_connect(
   uint32_t aiconfigtype,
   const char* aiconfigpath,
   boost::function<bool(const char*, uint32_t)> aisendfailure
   )
 {
   m_mser = new tools::mgt_serializecpp(aiconfigtype, aiconfigpath);
   return create_connect(aisendfailure);
 }
Exemple #18
0
int main()
{
	create_connect();
	create_drive_direct(-500 , -500);
	msleep(2000);
	create_drive_direct(300 , -300);
	msleep(500);
	create_disconnect();
}
Exemple #19
0
connect_client* connect_pool::peek()
{
	lock_.lock();
	if (alive_ == false)
	{
		time_t now = time(NULL);
		if (now - last_dead_ < retry_inter_)
		{
			lock_.unlock();
			return NULL;
		}
		alive_ = true;
	}

	connect_client* conn;

	std::list<connect_client*>::iterator it = pool_.begin();
	if (it != pool_.end())
	{
		conn = *it;
		pool_.erase(it);
		total_used_++;
		current_used_++;
		lock_.unlock();
		return conn;
	}
	else if (count_ >= max_)
	{
		logger_error("too many connections, max: %d, curr: %d,"
			" server: %s", count_, max_, addr_);
		lock_.unlock();
		return NULL;
	}

	conn = create_connect();
	if (conn->open() == false)
	{
		delete conn;
		alive_ = false;
		time(&last_dead_);
		(void) time(&last_dead_);
		lock_.unlock();
		return NULL;
	}

	count_++;

	total_used_++;
	current_used_++;

	lock_.unlock();

	conn->set_pool(this);

	return conn;
}
int main()
{
	create_connect();
	create_drive_direct(100,100);
	wait_for_milliseconds(2000);
	create_drive_direct(-200, 200);	
	wait_for_milliseconds(5000);
	create_stop();
	create_disconnect();
	return 0;
}
Exemple #21
0
int main()
{
    create_connect();
    enable_servos();
    set_create_total_angle(0);
    set_create_distance(0);

    WhichSide();
    CenterCamera();
    Lift();
}
Exemple #22
0
int main()
{
	create_connect();
	create_full();
	while(!(a_button_clicked())){
		display_clear();
		printf("cw:%d\nlw:%d\nrw:%d\n", get_create_cwdrop(), get_create_lwdrop(), get_create_rwdrop());
		msleep(20);
	}
	return 0;
}
int main()
{
	create_connect();
	while (side_button() == 0)
	{
		line_follow();
		msleep(10);
	}
	create_disconnect();
	return 0;
}
int main() 
{
	ROBOT = CREATE_ROBOT;
	create_connect();
	set_speeds();
	create_full();
	
	// test_modest_forward_backward();
	test_modest_left_right();
	
	return SUCCESS;
}
Exemple #25
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 #26
0
connect_client* connect_pool::peek()
{
	lock_->lock();
	if (alive_ == false)
	{
		time_t now = time(NULL);
		if (now - last_dead_ < retry_inter_)
		{
			lock_->unlock();
			return NULL;
		}
		alive_ = true;
	}

	connect_client* conn;

	std::list<connect_client*>::iterator it = pool_.begin();
	if (it != pool_.end())
	{
		conn = *it;
		pool_.erase(it);
		total_used_++;
		current_used_++;
		lock_->unlock();
		return conn;
	}
	else if (count_ >= max_)
	{
		lock_->unlock();
		return NULL;
	}

	conn = create_connect();
	if (conn->open() == false)
	{
		delete conn;
		alive_ = false;
		time(&last_dead_);
		(void) time(&last_dead_);
		lock_->unlock();
		return NULL;
	}

	count_++;

	total_used_++;
	current_used_++;

	lock_->unlock();
	return conn;
}
int main()
{
	create_connect();
	create_full();
	float sec = seconds();
	set_create_distance(0);
	create_drive_distance(50, get_pot_reading(1, 1, 50), FORWARDS);
	printf("distance traveled = %i, time = %f\n", get_create_distance(), seconds() - sec);
	//sleep(2);
	//create_spin_degrees(90, 300, LEFT);
	//printf("%d\n", i);
	create_disconnect();
	return 0;
}
void main()
{
	create_connect();
	enable_servos();
	set_each_analog_state(1,1,0,0,0,0,0,0);
	initialize();
	armPosBlockStack2();
	clawStack2();
	clawOpen();
	create_drive_straight(300);
	run_for(3, clawGrab);
	create_stop();
	clawGrab();
}
int main() 
{
	create_connect();
	while(1)
	{
		create_drive_direct(200, 300);
		if(get_create_rbump(0.01) ==1)
		{
			create_drive_direct(300, 200);
			msleep(800);
		}
	}
	create_stop();
	create_disconnect();
}
int main() 
{
	create_connect();
	create_drive_straight(500);
	sleep(2);
	create_drive_direct(500, -500);
	msleep(440);
	create_drive_straight(500);
	msleep(4200);
	create_drive_direct(-500, 500);
	msleep(375);
	create_drive_straight(500);
	msleep(1500);
	create_stop();
	create_disconnect();
}