forked from xuhao1/FOXTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagentxconfig.cpp
225 lines (184 loc) · 7.42 KB
/
agentxconfig.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "agentxconfig.h"
#include "ui_agentxconfig.h"
#include "FlightAgxSettings.h"
#include <string>
#include <QMessageBox>
AgentXConfig::AgentXConfig(QWidget *parent) :
QDialog(parent),
ui(new Ui::AgentXConfig)
{
ui->setupUi(this);
this->setWindowTitle("Config");
qDebug() << "Start AgentX Config page";
QStringList joystickNames = QJoysticks::getInstance()->deviceNames();
qDebug() << "Joysticks" << joystickNames;
QList<QJoystickDevice*> joysticks = QJoysticks::getInstance()->inputDevices();
qDebug() << "Joysicks" << joysticks.size();
QJoysticks::getInstance()->setVirtualJoystickEnabled (true);
connect(QJoysticks::getInstance(), &QJoysticks::buttonEvent, this, &AgentXConfig::buttonEvent);
if(settings->use_ft || settings->use_npclient) {
ui->DCtrl_Check->setCheckState(Qt::Checked);
} else {
ui->DCtrl_Check->setCheckState(Qt::Unchecked);
}
ui->Port_Input->setValue(settings->port);
ui->FPS_Input->setValue(settings->fps);
ui->CameraID_Input->setValue(settings->camera_id);
ui->DetectDura_Input->setValue(settings->detect_duration);
ui->IP_Input->setText(settings->udp_host.c_str());
//ui->SlerpRate_Input->setValue(settings->fsa_pnp_mixture_rate*100);
update_hotkeys();
// ui->FSAPnPOffset_disp->setDecMode();
// ui->FSAPnPOffset_disp->setDigitCount(5);
// ui->FSAPnPOffset_disp->display(settings->pitch_offset_fsa_pnp*RAD2DEG);
// ui->FSAPnPOffset_input->setValue(settings->pitch_offset_fsa_pnp*RAD2DEG/20*100);
ui->LandmarkModel_input->setValue(settings->landmark_detect_method);
ui->CameraGain_Input->setValue(settings->camera_gain*100);
ui->CameraExp_Input->setValue(settings->camera_expo*100);
ui->AutoExpo_Input->setChecked(settings->enable_auto_expo);
}
AgentXConfig::~AgentXConfig()
{
delete ui;
}
void AgentXConfig::on_EKF_Check_stateChanged(int arg1)
{
settings->use_ekf = arg1;
settings->set_value<bool>("use_ekf", arg1);
}
void AgentXConfig::on_DCtrl_Check_stateChanged(int arg1)
{
settings->use_ft = settings->use_npclient = arg1;
settings->set_value<bool>("use_ft", arg1);
settings->set_value<bool>("use_npclient", arg1);
}
void AgentXConfig::on_SendUDP_Check_stateChanged(int arg1)
{
settings->send_posedata_udp = arg1;
settings->set_value<bool>("send_posedata_udp", arg1);
}
void AgentXConfig::on_buttonBox_accepted()
{
if(settings->udp_host != ui->IP_Input->text().toUtf8().constData() || settings->port!=ui->Port_Input->value()) {
settings->udp_host = ui->IP_Input->text().toUtf8().constData();
settings->set_value<std::string>("udp_host", settings->udp_host);
settings->port = ui->Port_Input->value();
settings->set_value<int>("port", settings->port);
//TODO:Reset IP here
}
if (ui->CameraID_Input->value() != settings->camera_id || settings->fps != ui->FPS_Input->value()) {
settings->camera_id = ui->CameraID_Input->value();
settings->set_value<int>("camera_id", settings->camera_id);
settings->fps = ui->FPS_Input->value();
settings->set_value<double>("fps", settings->fps);
reset_camera();
}
settings->detect_duration = ui->DetectDura_Input->value();
settings->set_value<int>("detect_duration", settings->detect_duration);
qDebug() << "Save config.yaml to file";
settings->write_to_file();
}
void AgentXConfig::on_SlerpRate_Input_valueChanged(int value)
{
settings->fsa_pnp_mixture_rate = ((double)value)/100;
settings->set_value<double>("fsa_pnp_mixture_rate", settings->fsa_pnp_mixture_rate);
qDebug() << "fsa_pnp_mixture_rate" << settings->fsa_pnp_mixture_rate;
}
void AgentXConfig::on_Bind_HotKey_clicked(int key) {
mbox = new QMessageBox();
mbox->setText("Press any key to bind re-center key");
mbox->setStandardButtons(QMessageBox::Cancel);
wait_for_bind = key;
int ret = mbox->exec();
qDebug() << "MBox recturn" << ret;
}
void AgentXConfig::buttonEvent (const QJoystickButtonEvent& event) {
std::string joyname = event.joystick->name.toUtf8().constData();
int btn_id = event.button;
if(event.pressed && wait_for_bind >= 0) {
qDebug() << "Joystick" << event.joystick->name << " pressed " << event.button << " pressed" << event.pressed;
qDebug() << "Bind button to hotkey" << wait_for_bind;
settings->hotkey_joystick_names[wait_for_bind] = joyname;
settings->hotkey_joystick_buttons[wait_for_bind] = event.button;
if (mbox!=nullptr) {
mbox->done(0);
}
wait_for_bind = -1;
update_hotkeys();
return;
}
if (event.pressed) {
for (size_t i = 0; i < settings->hotkey_joystick_names.size(); i++) {
if(settings->hotkey_joystick_names[i] == joyname &&
settings->hotkey_joystick_buttons[i] == btn_id) {
qDebug() << "Hotkey" << i << "pressed";
if (i==0) {
recenter_hotkey_pressed();
} else if (i==1) {
pause_hotkey_pressed();
}
}
}
}
}
void AgentXConfig::on_Bind_HotKey2_clicked() {
on_Bind_HotKey_clicked(1);
ui->Hotkey2_Joystick->setText(settings->hotkey_joystick_names[1].c_str());
ui->Hotkey2_Button->setText(QString::number(settings->hotkey_joystick_buttons[1]));
}
void AgentXConfig::on_Bind_HotKey1_clicked() {
on_Bind_HotKey_clicked(0);
ui->Hotkey1_Joystick->setText(settings->hotkey_joystick_names[0].c_str());
ui->Hotkey1_Button->setText(QString::number(settings->hotkey_joystick_buttons[0]));
}
void AgentXConfig::on_FSAPnPOffset_input_valueChanged(int value)
{
float v = ((float)value)/100;
float offset_degree = v * 20;
float offset = offset_degree*DEG2RAD;
settings->pitch_offset_fsa_pnp = offset;
settings->set_value("pitch_offset_fsa_pnp", offset);
//ui->FSAPnPOffset_disp->display(offset_degree);
}
void AgentXConfig::on_LandmarkModel_input_valueChanged(int value)
{
settings->set_landmark_level(value);
settings->set_value("landmark_detect_method", value);
}
void AgentXConfig::on_Unbind_HotKey1_clicked()
{
settings->hotkey_joystick_names[0] = "";
settings->hotkey_joystick_buttons[0] = 0;
update_hotkeys();
}
void AgentXConfig::on_Unbind_HotKey2_clicked()
{
settings->hotkey_joystick_names[1] = "";
settings->hotkey_joystick_buttons[1] = 0;
update_hotkeys();
}
void AgentXConfig::update_hotkeys() {
ui->Hotkey1_Joystick->setText(settings->hotkey_joystick_names[0].c_str());
ui->Hotkey1_Button->setText(QString::number(settings->hotkey_joystick_buttons[0]));
ui->Hotkey2_Joystick->setText(settings->hotkey_joystick_names[1].c_str());
ui->Hotkey2_Button->setText(QString::number(settings->hotkey_joystick_buttons[1]));
}
void AgentXConfig::on_CameraGain_Input_valueChanged(int value)
{
// qDebug("Set camera gain");
set_camera_gain(((double)value)/100.0);
settings->camera_gain = ((double)value)/100.0;
settings->set_value("camera_gain", ((double)value)/100.0);
}
void AgentXConfig::on_CameraExp_Input_valueChanged(int value)
{
set_camera_expo(((double)value)/100.0);
settings->camera_expo = ((double)value)/100.0;
settings->set_value("camera_expo", ((double)value)/100.0);
}
void AgentXConfig::on_AutoExpo_Input_stateChanged(int arg1)
{
settings->enable_auto_expo = arg1;
set_camera_auto_expo(settings->enable_auto_expo);
settings->set_value("enable_auto_expo", settings->enable_auto_expo);
}