3 #include "ui_segwayrmp_gui.h" 6 #include <QtCore/QtConcurrentRun> 7 #include <QtGui/QErrorMessage> 8 #include <QtCore/QTimer> 10 #define JOY_DEADBAND 3200 11 #define JOY_MAX_VALUE 32768 27 SDL_Init(SDL_INIT_JOYSTICK);
28 SDL_JoystickEventState(SDL_ENABLE);
30 QTimer * timer =
new QTimer(
this);
37 connect(
ui->rmp_type, SIGNAL(currentIndexChanged(QString)),
this, SLOT(
rmpTypeChanged(QString)));
39 connect(
ui->refresh_button, SIGNAL(clicked()),
this, SLOT(
updateUSBList()));
50 connect(
ui->disable_motors_button, SIGNAL(clicked()),
this, SLOT(
onDisableMotors()));
54 connect(
ui->balance_lockout_button, SIGNAL(clicked()),
this, SLOT(
onBalanceLockout()));
55 connect(
ui->balance_unlock_button, SIGNAL(clicked()),
this, SLOT(
onBalanceUnlock()));
56 connect(
ui->send_config_button, SIGNAL(clicked()),
this, SLOT(
onSendConfig()));
61 timer->start(1000.0/25.0);
82 int lv_i = SDL_JoystickGetAxis(this->
joystick_,
ui->lv_axis_cb->currentIndex());
83 int av_i = SDL_JoystickGetAxis(this->
joystick_,
ui->av_axis_cb->currentIndex());
97 ui->lv_pb->setValue(
int(lv*100));
98 ui->av_pb->setValue(
int(av*100));
99 if (
ui->send_chb->checkState() == Qt::Checked && this->
rmp_) {
101 double lv_s =
ui->lv_scale_slider->value() / 100.0f;
102 double av_s =
ui->av_scale_slider->value() / 100.0f;
104 this->
rmp_->
moveCounts((
short int)(lv*1176*lv_s), (
short int)(av*1024*av_s));
105 }
catch (
const std::exception &e) {
106 qDebug() <<
"Error commanding base: " << e.what();
117 if (SDL_NumJoysticks() > 0) {
118 this->
joystick_ = SDL_JoystickOpen(index);
119 size_t num_axes = SDL_JoystickNumAxes(this->
joystick_);
120 ui->lv_axis_cb->clear();
121 ui->lv_axis_cb->setEnabled(
true);
122 ui->av_axis_cb->clear();
123 ui->av_axis_cb->setEnabled(
true);
124 ui->send_chb->setEnabled(
true);
126 ui->lv_axis_cb->addItem(
"No axes.");
127 ui->av_axis_cb->addItem(
"No axes.");
129 for (
size_t i = 0; i < num_axes; ++i) {
130 ui->lv_axis_cb->addItem(QString(
"Axis %1").arg(QString::number(i)));
131 ui->av_axis_cb->addItem(QString(
"Axis %1").arg(QString::number(i)));
134 ui->lv_axis_cb->setCurrentIndex(1);
135 ui->av_axis_cb->setCurrentIndex(0);
138 ui->lv_axis_cb->clear();
139 ui->lv_axis_cb->setEnabled(
false);
140 ui->av_axis_cb->clear();
141 ui->av_axis_cb->setEnabled(
false);
142 ui->send_chb->setEnabled(
false);
148 size_t num_joysticks = SDL_NumJoysticks();
149 ui->joy_list_cb->clear();
150 if (num_joysticks == 0) {
151 ui->joy_list_cb->addItem(
"No Joysticks Detected.");
153 for (
size_t i = 0; i < num_joysticks; ++i) {
154 ui->joy_list_cb->addItem(QString::fromAscii(SDL_JoystickName(i)));
160 rmp_->resetAllIntegrators();
190 rmp_->setBalanceModeLocking(
true);
196 rmp_->setBalanceModeLocking(
false);
202 rmp_->setMaxVelocityScaleFactor(
ui->max_vel_sb->value());
203 rmp_->setMaxAccelerationScaleFactor(
ui->max_accel_sb->value());
204 rmp_->setMaxTurnScaleFactor(
ui->max_turn_rate_sb->value());
205 rmp_->setCurrentLimitScaleFactor(
ui->current_limit_sb->value());
206 QString gain_schedule =
ui->gain_schedule_cb->currentText();
207 if (gain_schedule ==
"Light") {
210 if (gain_schedule ==
"Tall") {
213 if (gain_schedule ==
"Heavy") {
216 ui->statusbar->showMessage(
"Configurations sent to the Segway RMP", 3000);
221 emit
segwayLog(QString(
"%1: %2").arg(log_type, QString::fromStdString(msg)));
226 ui->statusbar->showMessage(log, 3000);
230 QString qss = QString::fromStdString(ss->str());
235 ui->status_label->setText(ss);
253 ui->connect_button->setText(
"Disconnect");
254 ui->connection_id->setEnabled(
false);
255 ui->connection_type->setEnabled(
false);
256 ui->rmp_type->setEnabled(
false);
257 ui->refresh_button->setEnabled(
false);
258 }
catch (
const std::exception &e) {
259 QString error = QString::fromAscii(e.what());
260 QErrorMessage error_msg;
261 QString error_string = QString(
"Error connecting: %1").arg(error);
262 qDebug() <<
"Error: " << error_string;
263 error_msg.showMessage(error_string);
273 ui->connect_button->setText(
"Connect");
274 ui->connection_id->setEnabled(
true);
275 ui->connection_type->setEnabled(
true);
276 ui->rmp_type->setEnabled(
true);
277 ui->refresh_button->setEnabled(
true);
283 ui->refresh_button->setEnabled(
true);
284 ui->connection_id->setEditable(
false);
287 }
else if (mode ==
"Serial") {
288 ui->refresh_button->setEnabled(
false);
289 ui->connection_id->setEditable(
true);
290 ui->connection_id->clear();
291 ui->connection_id->addItem(QString(
"/dev/ttyUSB0"));
297 if (type ==
"rmp50") {
300 if (type ==
"rmp100") {
303 if (type ==
"rmp200") {
306 if (type ==
"rmp400") {
312 ui->connection_id->clear();
314 ui->connection_id->addItem(entry);
324 std::vector<FT_DEVICE_LIST_INFO_NODE>::iterator it;
327 if (devices.size() == 0) {
330 for (it = devices.begin(); it != devices.end(); it++) {
331 QString line = QString(
"%1 : %2 - %3").arg(QString::number(i), QString(it->Description), QString(it->SerialNumber));
void configureUSBByIndex(int device_index, int baudrate=460800)
segwayrmp::InterfaceType interface_type_
void setLogMsgCallback(std::string log_level, LogMsgCallback callback)
boost::shared_ptr< SegwayStatus > Ptr
void onSegwayLog(QString, const std::string &)
void connect(bool reset_integrators=true)
void onResetIntegrators()
void onJoystickChanged(int)
QVector< QString > usb_devices_
void closeEvent(QCloseEvent *)
void handleSegwayLog(QString)
void setStatusCallback(SegwayStatusCallback callback)
void configureSerial(std::string port, int baudrate=460800)
MainWindow(QWidget *parent=0)
segwayrmp::SegwayRMP * rmp_
void onSegwayStatus(segwayrmp::SegwayStatus::Ptr)
void segwayStatus(QString)
void connectionTypeChanged(QString)
segwayrmp::SegwayRMPType rmp_type_
void handleSegwayStatus(QString)
void moveCounts(short int linear_counts, short int angular_counts)
void rmpTypeChanged(QString)
void onRequestPowerDown()
std::vector< FT_DEVICE_LIST_INFO_NODE > enumerateUSBDevices()