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