示例#1
0
int main()
{
	Dualshock3 joystick;
	joystick.connect();
	
	int err=serialPort.connect("//dev//ttyACM0");
	
	send_command('n', 0);

	while( 1 ) 	/* infinite loop */
	{

		joystick.getData();
		
		if (joystick.button[16]){
			serialPort.disconnect();
			close( joy_fd );
			system("sixad --stop &");
			exit(0);
		}
		
		joystick.getData();
		
		// Detect conflits and process input
		if (joystick.axis[12] != 0 && joystick.axis[13] != 0){
			// Rumbleeeeeee
			send_command('n', 0);
		}else if (joystick.axis[12] == 0 && joystick.axis[13] != 0){
			//input_processing(FWD, joystick.axis[13]);
			cout << "frente" << endl;
			send_command('f', joystick.axis[12]/547);
		}else if(joystick.axis[12] != 0 && joystick.axis[13] == 0){
			//input_processing(BCK, joystick.axis[12]);
			send_command('b', joystick.axis[13]/547);
		}else{
			send_command('n', 0);
		}
		
		joystick.getData();
		
		if (joystick.axis[0] > 0){
			send_command('r', joystick.axis[0]);
		}else if(joystick.axis[0] < 0){
			send_command('l', abs(joystick.axis[0]));
		}else{
			send_command('l', 0);
		}
	}

	serialPort.disconnect();
	close( joy_fd );	/* too bad we never get here */
	return 0;
}
示例#2
0
文件: moveax.c 项目: mllofriu/romina2
int main() {
	cout << "AX Control starts" << endl; // prints AX Control 
	int error=0; 
	int idAX12=0; 
	SerialPort serialPort; 
	if (serialPort.connect("/dev/ttyUSB0")!=0) {
		printf ("Serial port opened\n");
		// Sync Write: 0xFF 0xFF 0xFE(broadcast) [(L+1) * N + 4] 0x83(instruction)  0x20(location) 0x02(lenght of the data) 0x01(id1) lowvel1 hivel1 0x02(id2) lowvel2 hivel2 chk
		// This one sends vels to both motors with orientation
		sendVels(1,512,1, 2,512,0, &serialPort);
		serialPort.disconnect();
	} else {
		printf ("nCan't open serial port");
		error=-1;
	}
	 
	cout << endl << "AX Control ends" << endl; // prints AX Control
	return error;
}
示例#3
0
void my_handler(int signal){
           printf("Caught CTRL+C\n");
           serialPort.disconnect();
           exit(1);
}