dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
vehicletrim.cpp
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  *
26  * Additional note on redistribution: The copyright and license notices above
27  * must be maintained in each individual source file that is a derivative work
28  * of this source file; otherwise redistribution is prohibited.
29  */
30 
31 #include "vehicletrim.h"
33 
34 #include "actuatorcommand.h"
35 #include "actuatorsettings.h"
36 #include "stabilizationdesired.h"
37 #include "flightstatus.h"
38 #include "subtrimsettings.h"
39 #include "systemalarms.h"
40 
42 {
43 }
44 
46 {
47 }
48 
55 {
56  SystemAlarms *systemAlarms = SystemAlarms::GetInstance(getObjectManager());
57  FlightStatus *flightStatus = FlightStatus::GetInstance(getObjectManager());
58  StabilizationDesired *stabilizationDesired =
59  StabilizationDesired::GetInstance(getObjectManager());
60 
61  // Get SubTrimSettings UAVO
62  SubTrimSettings *subTrimSettings = SubTrimSettings::GetInstance(getObjectManager());
63  SubTrimSettings::DataFields subTrimSettingsData = subTrimSettings->getData();
64 
65  // Check that the receiver is present
66  if (systemAlarms->getAlarm_ManualControl() != SystemAlarms::ALARM_OK) {
68  }
69 
70  // Check that vehicle is disarmed
71  if (flightStatus->getArmed() != FlightStatus::ARMED_DISARMED) {
73  }
74 
75  // Check that vehicle is in stabilized{1,2,3} flight mode
76  if (flightStatus->getFlightMode() != FlightStatus::FLIGHTMODE_LEVELING
77  && flightStatus->getFlightMode() != FlightStatus::FLIGHTMODE_ALTITUDEHOLD
78  && flightStatus->getFlightMode() != FlightStatus::FLIGHTMODE_STABILIZED1
79  && flightStatus->getFlightMode() != FlightStatus::FLIGHTMODE_STABILIZED2
80  && flightStatus->getFlightMode() != FlightStatus::FLIGHTMODE_STABILIZED3) {
82  }
83 
84  // Check that pitch and roll axes are in attitude mode
85  if ((stabilizationDesired->getStabilizationMode_Pitch()
86  != StabilizationDesired::STABILIZATIONMODE_ATTITUDE)
87  || (stabilizationDesired->getStabilizationMode_Roll()
88  != StabilizationDesired::STABILIZATIONMODE_ATTITUDE)) {
90  }
91 
92  // Increment the current pitch and roll settings by what the pilot is requesting
93  subTrimSettingsData.Roll += stabilizationDesired->getRoll();
94  subTrimSettingsData.Pitch += stabilizationDesired->getPitch();
95  subTrimSettings->setData(subTrimSettingsData);
96  subTrimSettings->updated();
97 
98  // Inform GUI that trim function has successfully completed
99  emit trimCompleted();
100 
102 }
103 
111 {
112  SystemAlarms *systemAlarms = SystemAlarms::GetInstance(getObjectManager());
113  FlightStatus *flightStatus = FlightStatus::GetInstance(getObjectManager());
114  StabilizationDesired *stabilizationDesired =
115  StabilizationDesired::GetInstance(getObjectManager());
116 
117  // Get ActuatorCommand UAVO
118  ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(getObjectManager());
119  ActuatorCommand::DataFields actuatorCommandData = actuatorCommand->getData();
120 
121  // Get ActuatorSettings UAVO
122  ActuatorSettings *actuatorSettings = ActuatorSettings::GetInstance(getObjectManager());
123  ActuatorSettings::DataFields actuatorSettingsData = actuatorSettings->getData();
124 
125  // Check that the receiver is present
126  if (systemAlarms->getAlarm_ManualControl() != SystemAlarms::ALARM_OK) {
128  }
129 
130  // Ensure that vehicle is in full manual mode
131  if (flightStatus->getFlightMode() != FlightStatus::FLIGHTMODE_MANUAL
132  || stabilizationDesired->getStabilizationMode_Roll()
133  != StabilizationDesired::STABILIZATIONMODE_MANUAL
134  || stabilizationDesired->getStabilizationMode_Pitch()
135  != StabilizationDesired::STABILIZATIONMODE_MANUAL
136  || stabilizationDesired->getStabilizationMode_Yaw()
137  != StabilizationDesired::STABILIZATIONMODE_MANUAL) {
139  }
140 
141  // Iterate over output channel descriptions
142  QStringList channelDescriptions = ConfigVehicleTypeWidget::getChannelDescriptions();
143  for (int i = 0; i < channelDescriptions.length(); i++) {
144  if (channelDescriptions[i] == "FixedWingRoll1"
145  || channelDescriptions[i] == "FixedWingRoll2") {
146  int neutral = actuatorCommandData.Channel[i];
147  actuatorSettingsData.ChannelNeutral[i] = neutral;
148  } else if (channelDescriptions[i] == "FixedWingPitch1"
149  || channelDescriptions[i] == "FixedWingPitch2") {
150  int neutral = actuatorCommandData.Channel[i];
151  actuatorSettingsData.ChannelNeutral[i] = neutral;
152  } else if (channelDescriptions[i] == "FixedWingYaw1"
153  || channelDescriptions[i] == "FixedWingYaw2") {
154  int neutral = actuatorCommandData.Channel[i];
155  actuatorSettingsData.ChannelNeutral[i] = neutral;
156  }
157  }
158 
159  // Set the data to the UAVO, and inform the flight controller that the UAVO has been updated
160  actuatorSettings->setData(actuatorSettingsData);
161  actuatorSettings->updated();
162 
163  // Inform GUI that trim function has successfully completed
164  emit trimCompleted();
165 
166  return ACTUATOR_TRIM_SUCCESS;
167 }
168 
174 {
175  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
176  UAVObjectManager *objMngr = pm->getObject<UAVObjectManager>();
177  Q_ASSERT(objMngr);
178  return objMngr;
179 }
Gui-less support class for vehicle trimming.
autopilotLevelBiasMessages
Definition: vehicletrim.h:53
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
autopilotLevelBiasMessages setAutopilotBias()
VehicleTrim::setFixedWingTrimAutopilotBias Takes the desired roll and pitch, and sets that as the aut...
Definition: vehicletrim.cpp:54
for i
Definition: OPPlots.m:140
void trimCompleted()
Indicate that a trim process has successfully completed and the results saved to UAVO.
UAVObjectManager * getObjectManager()
Get the object manager.
actuatorTrimMessages setTrimActuators()
VehicleTrim::setFixedWingTrimActuators Reads the servo inputs from the transmitter, and sets these values as the neutral points.
static QStringList getChannelDescriptions()