Beispiel #1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    t = new QTimer(this);
    time = -1;
    ui->setupUi(this);
    connect(ui->pushButtonStart, SIGNAL(clicked()),
            this, SLOT(startExperiment()));
    connect(ui->okPushButton, SIGNAL(clicked()),
            this, SLOT(proceedToRusults()));
    connect(ui->ok2PushButton, SIGNAL(clicked()),
            this, SLOT(startOver()));
}
void KeyboardTeleoperation::keyboardLoop() {
	char c;
	bool dirty=false;

	// get the console in raw mode
	tcgetattr(kfd, &cooked);
	memcpy(&raw, &cooked, sizeof(struct termios));
	raw.c_lflag &=~ (ICANON | ECHO);
	// Setting a new line, then end of file
	raw.c_cc[VEOL] = 1;
	raw.c_cc[VEOF] = 2;
	tcsetattr(kfd, TCSANOW, &raw);

	puts("Reading from keyboard");
	puts("---------------------------");
	puts("Use 'WASD' to translate");
	puts("Use 'QE' to yaw");
	puts("Press 'U' or 'J' to increase or decrease translational speed");
	puts("Press 'I' or 'K' to increase or decrease translational speed");


	while(true) {
		// get the next event from the keyboard
		if(read(kfd, &c, 1) < 0) {
			perror("read():");
			exit(-1);
		}

		baseCommand.linear.x = 0;
		baseCommand.linear.y = 0;
		baseCommand.angular.z = 0;

		switch(c) {

		/* Move commands */
		case KEYCODE_W:
			baseCommand.linear.x = translationalSpeed;
			dirty = true;
			startExperiment();
			break;
		case KEYCODE_S:
			baseCommand.linear.x = - translationalSpeed;
			dirty = true;
			startExperiment();
			break;
		case KEYCODE_A:
			baseCommand.linear.y = translationalSpeed;
			dirty = true;
			startExperiment();
			break;
		case KEYCODE_D:
			baseCommand.linear.y = - translationalSpeed;
			dirty = true;
			startExperiment();
			break;
		case KEYCODE_Q:
			baseCommand.angular.z = rotationalSpeed;
			dirty = true;
			startExperiment();
			break;
		case KEYCODE_E:
			baseCommand.angular.z = - rotationalSpeed;
			dirty = true;
			startExperiment();
			break;

		/* Configuration commands */
		case KEYCODE_U:
			translationalSpeed += incrementRate;
			ROS_INFO("New translational velocity = %f", translationalSpeed);
			break;
		case KEYCODE_J:
			translationalSpeed -= incrementRate;
			ROS_INFO("New translational velocity = %f", translationalSpeed);
			break;
		case KEYCODE_I:
			rotationalSpeed += incrementRate;
			ROS_INFO("New rotational velocity = %f", rotationalSpeed);
			break;
		case KEYCODE_K:
			rotationalSpeed -= incrementRate;
			ROS_INFO("New rotational velocity = %f", rotationalSpeed);
			break;

		default:
			stopExperiment();
		}


		if (dirty == true) {
			baseCommandPublisher.publish(baseCommand);
		}
	}
}