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