[3] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[3] | 4 | // %flair:license}
|
---|
| 5 | // created: 2013/04/29
|
---|
| 6 | // filename: BlCtrlV2_x4_speed.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: objet integrant les moteurs i2c, controle en vitesse
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #include "BlCtrlV2_x4_speed.h"
|
---|
| 19 | #include "I2cPort.h"
|
---|
| 20 | #include <TabWidget.h>
|
---|
| 21 | #include <Tab.h>
|
---|
| 22 | #include <GroupBox.h>
|
---|
| 23 | #include <SpinBox.h>
|
---|
| 24 | #include <DoubleSpinBox.h>
|
---|
| 25 | #include <ComboBox.h>
|
---|
| 26 | #include <PushButton.h>
|
---|
| 27 | #include <cvmatrix.h>
|
---|
| 28 | #include <Mutex.h>
|
---|
| 29 | #include <FrameworkManager.h>
|
---|
| 30 | #include <DataPlot1D.h>
|
---|
| 31 | #include <math.h>
|
---|
| 32 | #include <string.h>
|
---|
| 33 |
|
---|
| 34 | #define TAU_US 1000
|
---|
| 35 |
|
---|
| 36 | using std::string;
|
---|
| 37 | using namespace flair::core;
|
---|
| 38 | using namespace flair::gui;
|
---|
| 39 |
|
---|
[15] | 40 | namespace flair {
|
---|
| 41 | namespace actuator {
|
---|
[137] | 42 | BlCtrlV2_x4_speed::BlCtrlV2_x4_speed(string name,I2cPort *i2cport, uint8_t base_address,
|
---|
[15] | 43 | uint8_t priority)
|
---|
[137] | 44 | : Thread(getFrameworkManager(), name, priority), IODevice(getFrameworkManager(), name) {
|
---|
[15] | 45 | this->i2cport = i2cport;
|
---|
| 46 | slave_address = base_address;
|
---|
| 47 | tested_motor = -1;
|
---|
| 48 | enabled = false;
|
---|
| 49 | int_av_g = 0;
|
---|
| 50 | int_av_d = 0;
|
---|
| 51 | int_ar_g = 0;
|
---|
| 52 | int_ar_d = 0;
|
---|
[3] | 53 |
|
---|
[15] | 54 | // flight time
|
---|
| 55 | FILE *file;
|
---|
| 56 | file = fopen("/etc/flight_time", "r");
|
---|
| 57 | if (file == NULL) {
|
---|
| 58 | Printf("fichier d'info de vol vide\n");
|
---|
| 59 | time_sec = 0;
|
---|
| 60 | } else {
|
---|
| 61 | char ligne[32];
|
---|
| 62 | fgets(ligne, 32, file);
|
---|
| 63 | time_sec = atoi(ligne);
|
---|
| 64 | Printf("temps de vol total: %is = %imin = %ih\n", time_sec, time_sec / 60,
|
---|
| 65 | time_sec / 3600);
|
---|
| 66 | fclose(file);
|
---|
| 67 | }
|
---|
[3] | 68 |
|
---|
[15] | 69 | // station sol
|
---|
[137] | 70 | main_tab = new Tab(getFrameworkManager()->GetTabWidget(), name);
|
---|
[15] | 71 | tab = new TabWidget(main_tab->NewRow(), name);
|
---|
| 72 | Tab *sensor_tab = new Tab(tab, "Reglages");
|
---|
| 73 | reglages_groupbox = new GroupBox(sensor_tab->NewRow(), name);
|
---|
| 74 | poles = new SpinBox(reglages_groupbox->NewRow(), "nb poles", 0, 255, 1);
|
---|
| 75 | kp = new DoubleSpinBox(reglages_groupbox->LastRowLastCol(), "kp", 0., 255,
|
---|
| 76 | 0.001, 4);
|
---|
| 77 | ki = new DoubleSpinBox(reglages_groupbox->LastRowLastCol(), "ki", 0., 255,
|
---|
| 78 | 0.001, 4);
|
---|
| 79 | min = new SpinBox(reglages_groupbox->NewRow(), "min pwm", 0., 2048, 1);
|
---|
| 80 | max =
|
---|
| 81 | new SpinBox(reglages_groupbox->LastRowLastCol(), "max pwm", 0., 2048, 1);
|
---|
| 82 | test = new SpinBox(reglages_groupbox->LastRowLastCol(), "test value", 0.,
|
---|
| 83 | 2048, 1);
|
---|
| 84 | start_value = new SpinBox(reglages_groupbox->NewRow(), "valeur demarrage", 0,
|
---|
| 85 | 10000, 10);
|
---|
| 86 | trim = new DoubleSpinBox(reglages_groupbox->LastRowLastCol(), "pas decollage",
|
---|
| 87 | 0, 1000, .1);
|
---|
[3] | 88 |
|
---|
[15] | 89 | av_g = new ComboBox(reglages_groupbox->NewRow(), "avant gauche");
|
---|
| 90 | av_g->AddItem("1");
|
---|
| 91 | av_g->AddItem("2");
|
---|
| 92 | av_g->AddItem("3");
|
---|
| 93 | av_g->AddItem("4");
|
---|
| 94 | button_avg = new PushButton(reglages_groupbox->LastRowLastCol(), "test avg");
|
---|
[3] | 95 |
|
---|
[15] | 96 | av_d = new ComboBox(reglages_groupbox->LastRowLastCol(), "avant droite:");
|
---|
| 97 | av_d->AddItem("1");
|
---|
| 98 | av_d->AddItem("2");
|
---|
| 99 | av_d->AddItem("3");
|
---|
| 100 | av_d->AddItem("4");
|
---|
| 101 | button_avd = new PushButton(reglages_groupbox->LastRowLastCol(), "test avd");
|
---|
[3] | 102 |
|
---|
[15] | 103 | ar_g = new ComboBox(reglages_groupbox->NewRow(), "arriere gauche:");
|
---|
| 104 | ar_g->AddItem("1");
|
---|
| 105 | ar_g->AddItem("2");
|
---|
| 106 | ar_g->AddItem("3");
|
---|
| 107 | ar_g->AddItem("4");
|
---|
| 108 | button_arg = new PushButton(reglages_groupbox->LastRowLastCol(), "test arg");
|
---|
[3] | 109 |
|
---|
[15] | 110 | ar_d = new ComboBox(reglages_groupbox->LastRowLastCol(), "arriere droite:");
|
---|
| 111 | ar_d->AddItem("1");
|
---|
| 112 | ar_d->AddItem("2");
|
---|
| 113 | ar_d->AddItem("3");
|
---|
| 114 | ar_d->AddItem("4");
|
---|
| 115 | button_ard = new PushButton(reglages_groupbox->LastRowLastCol(), "test ard");
|
---|
[3] | 116 |
|
---|
[15] | 117 | pas = new ComboBox(reglages_groupbox->NewRow(), "pas helice avant gauche:");
|
---|
| 118 | pas->AddItem("normal");
|
---|
| 119 | pas->AddItem("inverse");
|
---|
[3] | 120 |
|
---|
[15] | 121 | input = new cvmatrix((IODevice *)this, 8, 1, floatType);
|
---|
[3] | 122 |
|
---|
[15] | 123 | cvmatrix_descriptor *desc = new cvmatrix_descriptor(4, 2);
|
---|
| 124 | desc->SetElementName(0, 0, "avant gauche");
|
---|
| 125 | desc->SetElementName(1, 0, "arriere droite");
|
---|
| 126 | desc->SetElementName(2, 0, "avant droite");
|
---|
| 127 | desc->SetElementName(3, 0, "arriere gauche");
|
---|
[3] | 128 |
|
---|
[15] | 129 | desc->SetElementName(0, 1, "cons avant gauche");
|
---|
| 130 | desc->SetElementName(1, 1, "cons arriere droite");
|
---|
| 131 | desc->SetElementName(2, 1, "cons avant droite");
|
---|
| 132 | desc->SetElementName(3, 1, "cons arriere gauche");
|
---|
| 133 | output = new cvmatrix((IODevice *)this, desc, floatType);
|
---|
[148] | 134 | delete desc;
|
---|
| 135 |
|
---|
[157] | 136 | SetIsReady(true);
|
---|
| 137 |
|
---|
[15] | 138 | /*
|
---|
[3] | 139 |
|
---|
[15] | 140 | //le 3ieme lu est la tension batteire
|
---|
| 141 | if(i2c_mutex!=NULL) i2c_mutex->GetMutex();
|
---|
| 142 | uint16_t pwm_moteur;
|
---|
| 143 | pwm_moteur=0;
|
---|
| 144 | ssize_t read;
|
---|
| 145 | uint8_t rx[8];
|
---|
| 146 | SetSlave(slave_address);
|
---|
[3] | 147 |
|
---|
[15] | 148 | for(int j=0;j<10;j++)
|
---|
| 149 | {
|
---|
[3] | 150 |
|
---|
| 151 |
|
---|
[15] | 152 | WriteValue(pwm_moteur);
|
---|
[3] | 153 |
|
---|
| 154 |
|
---|
[15] | 155 | read = rt_dev_read(i2c_fd, rx, sizeof(rx));
|
---|
[3] | 156 |
|
---|
[15] | 157 | if(read<0)
|
---|
| 158 | {
|
---|
| 159 | rt_printf("BlCtrlV2_x4_speed::BlCtrlV2_x4_speed: %s, erreur
|
---|
| 160 | rt_dev_read (%s)\n",IODevice::ObjectName().c_str(),strerror(-read));
|
---|
| 161 | }
|
---|
| 162 | else if (read != sizeof(rx))
|
---|
| 163 | {
|
---|
| 164 | rt_printf("BlCtrlV2_x4_speed::BlCtrlV2_x4_speed: %s, erreur
|
---|
| 165 | rt_dev_read %i/2\n",IODevice::ObjectName().c_str(),read);
|
---|
[3] | 166 |
|
---|
[15] | 167 | }
|
---|
| 168 | for(int i=0;i<sizeof(rx);i++) printf("%i ",rx[i]);
|
---|
[3] | 169 |
|
---|
[15] | 170 | printf("\n");
|
---|
[3] | 171 |
|
---|
[15] | 172 | }
|
---|
[3] | 173 |
|
---|
[15] | 174 | if(i2c_mutex!=NULL) i2c_mutex->ReleaseMutex();*/
|
---|
[3] | 175 | }
|
---|
| 176 |
|
---|
[15] | 177 | BlCtrlV2_x4_speed::~BlCtrlV2_x4_speed(void) {
|
---|
| 178 | SafeStop();
|
---|
| 179 | Join();
|
---|
| 180 | delete main_tab;
|
---|
[3] | 181 | }
|
---|
| 182 |
|
---|
[15] | 183 | void BlCtrlV2_x4_speed::UseDefaultPlot(void) {
|
---|
| 184 | Tab *plot_tab = new Tab(tab, "Mesures");
|
---|
| 185 | DataPlot1D *av_g_plot = new DataPlot1D(plot_tab->NewRow(), "avg", 0, 10000);
|
---|
| 186 | av_g_plot->AddCurve(output->Element(0, 0));
|
---|
| 187 | av_g_plot->AddCurve(output->Element(0, 1), DataPlot::Blue);
|
---|
| 188 | DataPlot1D *av_d_plot =
|
---|
| 189 | new DataPlot1D(plot_tab->LastRowLastCol(), "avd", 0, 10000);
|
---|
| 190 | av_d_plot->AddCurve(output->Element(2, 0));
|
---|
| 191 | av_d_plot->AddCurve(output->Element(2, 1), DataPlot::Blue);
|
---|
| 192 | DataPlot1D *ar_g_plot = new DataPlot1D(plot_tab->NewRow(), "arg", 0, 10000);
|
---|
| 193 | ar_g_plot->AddCurve(output->Element(3, 0));
|
---|
| 194 | ar_g_plot->AddCurve(output->Element(3, 1), DataPlot::Blue);
|
---|
| 195 | DataPlot1D *ar_d_plot =
|
---|
| 196 | new DataPlot1D(plot_tab->LastRowLastCol(), "ard", 0, 10000);
|
---|
| 197 | ar_d_plot->AddCurve(output->Element(1, 0));
|
---|
| 198 | ar_d_plot->AddCurve(output->Element(1, 1), DataPlot::Blue);
|
---|
[3] | 199 | }
|
---|
| 200 |
|
---|
[15] | 201 | float BlCtrlV2_x4_speed::TrimValue(void) { return (float)trim->Value(); }
|
---|
[3] | 202 |
|
---|
[15] | 203 | int BlCtrlV2_x4_speed::StartValue(void) { return start_value->Value(); }
|
---|
[3] | 204 |
|
---|
[15] | 205 | void BlCtrlV2_x4_speed::Run(void) {
|
---|
| 206 | WarnUponSwitches(true);
|
---|
[3] | 207 |
|
---|
[15] | 208 | SetPeriodUS(TAU_US);
|
---|
[3] | 209 |
|
---|
[15] | 210 | while (!ToBeStopped()) {
|
---|
| 211 | WaitPeriod();
|
---|
[3] | 212 |
|
---|
[15] | 213 | Update();
|
---|
| 214 | }
|
---|
[3] | 215 |
|
---|
[15] | 216 | WarnUponSwitches(false);
|
---|
[3] | 217 | }
|
---|
| 218 |
|
---|
[15] | 219 | void BlCtrlV2_x4_speed::Update(void) {
|
---|
| 220 | float u_roll, u_pitch, u_yaw, u_gaz;
|
---|
| 221 | float trim_roll, trim_pitch, trim_yaw;
|
---|
| 222 | float pwm[4];
|
---|
| 223 | uint16_t pwm_moteur[4];
|
---|
[3] | 224 |
|
---|
[15] | 225 | // on prend une fois pour toute le mutex et on fait des accès directs
|
---|
| 226 | input->GetMutex();
|
---|
[3] | 227 |
|
---|
[15] | 228 | u_roll = input->ValueNoMutex(0, 0);
|
---|
| 229 | u_pitch = input->ValueNoMutex(1, 0);
|
---|
| 230 | u_yaw = input->ValueNoMutex(2, 0);
|
---|
| 231 | u_gaz =
|
---|
| 232 | input->ValueNoMutex(3, 0) +
|
---|
| 233 | input->ValueNoMutex(7, 0) * input->ValueNoMutex(7, 0); // ugaz+trim*trim
|
---|
| 234 | trim_roll = input->ValueNoMutex(4, 0);
|
---|
| 235 | trim_pitch = input->ValueNoMutex(5, 0);
|
---|
| 236 | trim_yaw = input->ValueNoMutex(6, 0);
|
---|
[3] | 237 |
|
---|
[15] | 238 | input->ReleaseMutex();
|
---|
[3] | 239 |
|
---|
[15] | 240 | if (pas->CurrentIndex() == 1) {
|
---|
| 241 | trim_yaw = -trim_yaw;
|
---|
| 242 | u_yaw = -u_yaw;
|
---|
| 243 | }
|
---|
[3] | 244 |
|
---|
[15] | 245 | // rt_printf("%f %f %f %f\n",u_roll,u_pitch,u_yaw,u_gaz);
|
---|
| 246 | // if(u_gaz!=0) rt_printf("gaz: %f\n",u_gaz);
|
---|
[3] | 247 |
|
---|
[15] | 248 | // avant gauche
|
---|
| 249 | if (u_gaz + u_pitch + u_roll + u_yaw > 0) {
|
---|
| 250 | pwm[0] = trim_pitch + trim_roll + trim_yaw +
|
---|
| 251 | sqrtf(u_gaz + u_pitch + u_roll + u_yaw);
|
---|
| 252 | } else {
|
---|
| 253 | pwm[0] = trim_pitch + trim_roll + trim_yaw;
|
---|
| 254 | }
|
---|
[3] | 255 |
|
---|
[15] | 256 | // arriere gauche
|
---|
| 257 | if (u_gaz - u_pitch + u_roll - u_yaw > 0) {
|
---|
| 258 | pwm[3] = -trim_pitch + trim_roll - trim_yaw +
|
---|
| 259 | sqrtf(u_gaz - u_pitch + u_roll - u_yaw);
|
---|
| 260 | } else {
|
---|
| 261 | pwm[3] = -trim_pitch + trim_roll - trim_yaw;
|
---|
| 262 | }
|
---|
[3] | 263 |
|
---|
[15] | 264 | // arriere droit
|
---|
| 265 | if (u_gaz - u_pitch - u_roll + u_yaw > 0) {
|
---|
| 266 | pwm[1] = -trim_pitch - trim_roll + trim_yaw +
|
---|
| 267 | sqrtf(u_gaz - u_pitch - u_roll + u_yaw);
|
---|
| 268 | } else {
|
---|
| 269 | pwm[1] = -trim_pitch - trim_roll + trim_yaw;
|
---|
| 270 | }
|
---|
[3] | 271 |
|
---|
[15] | 272 | // avant droit
|
---|
| 273 | if (u_gaz + u_pitch - u_roll - u_yaw > 0) {
|
---|
| 274 | pwm[2] = trim_pitch - trim_roll - trim_yaw +
|
---|
| 275 | sqrtf(u_gaz + u_pitch - u_roll - u_yaw);
|
---|
| 276 | } else {
|
---|
| 277 | pwm[2] = trim_pitch - trim_roll - trim_yaw;
|
---|
| 278 | }
|
---|
[3] | 279 |
|
---|
[15] | 280 | int_av_g += ki->Value() * (pwm[0] - speed_av_g);
|
---|
| 281 | pwm[0] = kp->Value() * (pwm[0] - speed_av_g) + int_av_g;
|
---|
[3] | 282 |
|
---|
[15] | 283 | int_ar_g += ki->Value() * (pwm[3] - speed_ar_g);
|
---|
| 284 | pwm[3] = kp->Value() * (pwm[3] - speed_ar_g) + int_ar_g;
|
---|
[3] | 285 |
|
---|
[15] | 286 | int_ar_d += ki->Value() * (pwm[1] - speed_ar_d);
|
---|
| 287 | pwm[1] = kp->Value() * (pwm[1] - speed_ar_d) + int_ar_d;
|
---|
[3] | 288 |
|
---|
[15] | 289 | int_av_d += ki->Value() * (pwm[2] - speed_av_d);
|
---|
| 290 | pwm[2] = kp->Value() * (pwm[2] - speed_av_d) + int_av_d;
|
---|
[3] | 291 |
|
---|
[15] | 292 | // rt_printf("%f\n",pwm[0]);
|
---|
| 293 | for (int i = 0; i < 4; i++)
|
---|
| 294 | pwm_moteur[i] = SatPWM(pwm[i], min->Value(), max->Value());
|
---|
[3] | 295 |
|
---|
[15] | 296 | if (button_avg->Clicked() == true) {
|
---|
| 297 | tested_motor = 0;
|
---|
| 298 | StartTest();
|
---|
| 299 | }
|
---|
| 300 | if (button_avd->Clicked() == true) {
|
---|
| 301 | tested_motor = 2;
|
---|
| 302 | StartTest();
|
---|
| 303 | }
|
---|
| 304 | if (button_arg->Clicked() == true) {
|
---|
| 305 | tested_motor = 3;
|
---|
| 306 | StartTest();
|
---|
| 307 | }
|
---|
| 308 | if (button_ard->Clicked() == true) {
|
---|
| 309 | tested_motor = 1;
|
---|
| 310 | StartTest();
|
---|
| 311 | }
|
---|
[3] | 312 |
|
---|
[15] | 313 | if (tested_motor != -1) {
|
---|
| 314 | for (int i = 0; i < 4; i++) {
|
---|
| 315 | pwm_moteur[i] = 0;
|
---|
[3] | 316 | }
|
---|
[15] | 317 | pwm_moteur[tested_motor] = (uint16_t)test->Value();
|
---|
[3] | 318 |
|
---|
[15] | 319 | if (GetTime() > (start_time + 2 * 1000000000))
|
---|
| 320 | StopTest();
|
---|
| 321 | }
|
---|
[3] | 322 |
|
---|
[15] | 323 | i2cport->GetMutex();
|
---|
[3] | 324 |
|
---|
[15] | 325 | if (enabled == true) {
|
---|
| 326 | i2cport->SetSlave(slave_address + av_g->CurrentIndex());
|
---|
| 327 | WriteValue(pwm_moteur[0]);
|
---|
[3] | 328 |
|
---|
[15] | 329 | i2cport->SetSlave(slave_address + av_d->CurrentIndex());
|
---|
| 330 | WriteValue(pwm_moteur[2]);
|
---|
[3] | 331 |
|
---|
[15] | 332 | i2cport->SetSlave(slave_address + ar_g->CurrentIndex());
|
---|
| 333 | WriteValue(pwm_moteur[3]);
|
---|
[3] | 334 |
|
---|
[15] | 335 | i2cport->SetSlave(slave_address + ar_d->CurrentIndex());
|
---|
| 336 | WriteValue(pwm_moteur[1]);
|
---|
[3] | 337 |
|
---|
[15] | 338 | } else {
|
---|
| 339 | for (int i = 0; i < 4; i++) {
|
---|
| 340 | i2cport->SetSlave(slave_address + i);
|
---|
| 341 | WriteValue(0);
|
---|
[3] | 342 | }
|
---|
[15] | 343 | int_av_g = 0;
|
---|
| 344 | int_av_d = 0;
|
---|
| 345 | int_ar_g = 0;
|
---|
| 346 | int_ar_d = 0;
|
---|
| 347 | }
|
---|
[3] | 348 |
|
---|
[15] | 349 | i2cport->SetSlave(slave_address + av_g->CurrentIndex());
|
---|
| 350 | speed_av_g = GetSpeed();
|
---|
[3] | 351 |
|
---|
[15] | 352 | i2cport->SetSlave(slave_address + av_d->CurrentIndex());
|
---|
| 353 | speed_av_d = GetSpeed();
|
---|
[3] | 354 |
|
---|
[15] | 355 | i2cport->SetSlave(slave_address + ar_g->CurrentIndex());
|
---|
| 356 | speed_ar_g = GetSpeed();
|
---|
[3] | 357 |
|
---|
[15] | 358 | i2cport->SetSlave(slave_address + ar_d->CurrentIndex());
|
---|
| 359 | speed_ar_d = GetSpeed();
|
---|
[3] | 360 |
|
---|
[15] | 361 | i2cport->ReleaseMutex();
|
---|
[3] | 362 |
|
---|
[15] | 363 | // on prend une fois pour toute le mutex et on fait des accès directs
|
---|
| 364 | output->GetMutex();
|
---|
| 365 | output->SetValueNoMutex(0, 0, speed_av_g);
|
---|
| 366 | output->SetValueNoMutex(1, 0, speed_ar_d);
|
---|
| 367 | output->SetValueNoMutex(2, 0, speed_av_d);
|
---|
| 368 | output->SetValueNoMutex(3, 0, speed_ar_g);
|
---|
| 369 | // rt_printf("%i %i %i
|
---|
| 370 | // %i\n",pwm_moteur[0],pwm_moteur[1],pwm_moteur[2],pwm_moteur[3]);
|
---|
| 371 | output->ReleaseMutex();
|
---|
[3] | 372 |
|
---|
[15] | 373 | output->SetDataTime(GetTime());
|
---|
| 374 | ProcessUpdate(output);
|
---|
[3] | 375 | }
|
---|
| 376 |
|
---|
[15] | 377 | void BlCtrlV2_x4_speed::StartTest(void) {
|
---|
| 378 | start_time = GetTime();
|
---|
| 379 | SetEnabled(true);
|
---|
[3] | 380 | }
|
---|
| 381 |
|
---|
[15] | 382 | void BlCtrlV2_x4_speed::StopTest(void) {
|
---|
| 383 | SetEnabled(false);
|
---|
| 384 | tested_motor = -1;
|
---|
[3] | 385 | }
|
---|
| 386 |
|
---|
[15] | 387 | uint16_t BlCtrlV2_x4_speed::SatPWM(float vel_cons, uint16_t min, uint16_t max) {
|
---|
| 388 | uint16_t sat_value = (uint16_t)vel_cons;
|
---|
[3] | 389 |
|
---|
[15] | 390 | if (vel_cons > ((float)sat_value + 0.5))
|
---|
| 391 | sat_value++;
|
---|
[3] | 392 |
|
---|
[15] | 393 | if (vel_cons < (float)min)
|
---|
| 394 | sat_value = min;
|
---|
| 395 | if (vel_cons > (float)max)
|
---|
| 396 | sat_value = max;
|
---|
[3] | 397 |
|
---|
| 398 | return sat_value;
|
---|
| 399 | }
|
---|
| 400 |
|
---|
[15] | 401 | void BlCtrlV2_x4_speed::LockUserInterface(void) {
|
---|
| 402 | reglages_groupbox->setEnabled(false);
|
---|
[3] | 403 | }
|
---|
| 404 |
|
---|
[15] | 405 | void BlCtrlV2_x4_speed::UnlockUserInterface(void) {
|
---|
| 406 | reglages_groupbox->setEnabled(true);
|
---|
[3] | 407 | }
|
---|
| 408 |
|
---|
[15] | 409 | void BlCtrlV2_x4_speed::SetEnabled(bool status) {
|
---|
| 410 | enabled = status;
|
---|
| 411 | if (enabled == true) {
|
---|
| 412 | LockUserInterface();
|
---|
[3] | 413 |
|
---|
[15] | 414 | flight_start_time = GetTime();
|
---|
| 415 | } else {
|
---|
| 416 | UnlockUserInterface();
|
---|
[3] | 417 |
|
---|
[15] | 418 | Time now = GetTime();
|
---|
| 419 | int t_sec;
|
---|
| 420 | FILE *file;
|
---|
| 421 | char ligne[32];
|
---|
[3] | 422 |
|
---|
[15] | 423 | t_sec = (now - flight_start_time) / 1000000000;
|
---|
| 424 | time_sec += t_sec;
|
---|
[3] | 425 |
|
---|
[15] | 426 | Printf("temps de vol: %is = %imin\n", t_sec, t_sec / 60);
|
---|
| 427 | Printf("temps de vol total: %is = %imin = %ih\n", time_sec, time_sec / 60,
|
---|
| 428 | time_sec / 3600);
|
---|
[3] | 429 |
|
---|
[15] | 430 | file = fopen("/etc/flight_time", "w");
|
---|
| 431 | if (file == NULL) {
|
---|
| 432 | Thread::Err("Erreur a l'ouverture du fichier d'info vol\n");
|
---|
| 433 | } else {
|
---|
| 434 | sprintf(ligne, "%i", time_sec);
|
---|
| 435 | fputs(ligne, file);
|
---|
| 436 | fclose(file);
|
---|
[3] | 437 | }
|
---|
[15] | 438 | }
|
---|
[3] | 439 | }
|
---|
| 440 |
|
---|
[15] | 441 | void BlCtrlV2_x4_speed::SetUroll(float value) { input->SetValue(0, 0, value); }
|
---|
[3] | 442 |
|
---|
[15] | 443 | void BlCtrlV2_x4_speed::SetUpitch(float value) { input->SetValue(1, 0, value); }
|
---|
[3] | 444 |
|
---|
[15] | 445 | void BlCtrlV2_x4_speed::SetUyaw(float value) { input->SetValue(2, 0, value); }
|
---|
[3] | 446 |
|
---|
[15] | 447 | void BlCtrlV2_x4_speed::SetUgaz(float value) { input->SetValue(3, 0, value); }
|
---|
[3] | 448 |
|
---|
[15] | 449 | void BlCtrlV2_x4_speed::SetRollTrim(float value) {
|
---|
| 450 | input->SetValue(4, 0, value);
|
---|
[3] | 451 | }
|
---|
| 452 |
|
---|
[15] | 453 | void BlCtrlV2_x4_speed::SetPitchTrim(float value) {
|
---|
| 454 | input->SetValue(5, 0, value);
|
---|
[3] | 455 | }
|
---|
| 456 |
|
---|
[15] | 457 | void BlCtrlV2_x4_speed::SetYawTrim(float value) {
|
---|
| 458 | input->SetValue(6, 0, value);
|
---|
[3] | 459 | }
|
---|
| 460 |
|
---|
[15] | 461 | void BlCtrlV2_x4_speed::SetGazTrim(float value) {
|
---|
| 462 | input->SetValue(7, 0, value);
|
---|
[3] | 463 | }
|
---|
| 464 |
|
---|
[15] | 465 | void BlCtrlV2_x4_speed::WriteValue(uint16_t value) {
|
---|
| 466 | unsigned char tx[2];
|
---|
| 467 | ssize_t written;
|
---|
[3] | 468 |
|
---|
[15] | 469 | tx[0] = (unsigned char)(value >> 3); // msb
|
---|
| 470 | tx[1] = 16 + 8 + (value & 0x07); // 16+8 pour recuperer la vitesse
|
---|
| 471 | written = i2cport->Write(tx, 2);
|
---|
| 472 | if (written < 0) {
|
---|
| 473 | Thread::Err("erreur rt_dev_write (%s)\n", strerror(-written));
|
---|
| 474 | } else if (written != 2) {
|
---|
| 475 | Thread::Err("erreur rt_dev_write %i/2\n", written);
|
---|
| 476 | }
|
---|
[3] | 477 | }
|
---|
| 478 |
|
---|
[15] | 479 | float BlCtrlV2_x4_speed::GetSpeed(void) {
|
---|
| 480 | ssize_t read;
|
---|
| 481 | uint8_t value;
|
---|
| 482 | read = i2cport->Read(&value, 1);
|
---|
[3] | 483 |
|
---|
[15] | 484 | if (read < 0) {
|
---|
| 485 | Thread::Err("erreur rt_dev_read (%s)\n", strerror(-read));
|
---|
| 486 | } else if (read != 1) {
|
---|
| 487 | Thread::Err("erreur rt_dev_read %i/2\n", read);
|
---|
| 488 | }
|
---|
[3] | 489 |
|
---|
[15] | 490 | return value * 780. / poles->Value();
|
---|
[3] | 491 | }
|
---|
| 492 |
|
---|
| 493 | } // end namespace actuator
|
---|
| 494 | } // end namespace framewor
|
---|