39 #include "physical_constants.h"
41 #include "flightstatus.h"
42 #include "gpsposition.h"
43 #include "homelocation.h"
44 #include "loitercommand.h"
45 #include "pathdesired.h"
46 #include "positionactual.h"
47 #include "tabletinfo.h"
48 #include "systemsettings.h"
54 #define HOME_ALTITUDE_OFFSET 15
55 #define FOLLOWME_RADIUS 20
60 if (TabletInfoInitialize() == -1) {
81 TabletInfoData tabletInfo;
82 TabletInfoGet(&tabletInfo);
84 FlightStatusData flightStatus;
85 FlightStatusGet(&flightStatus);
87 if (PathDesiredHandle() == NULL)
91 PathDesiredGet(&pathDesired);
93 uint8_t
mode = flightStatus.FlightMode;
95 switch(tabletInfo.TabletModeDesired) {
96 case TABLETINFO_TABLETMODEDESIRED_POSITIONHOLD:
100 mode = FLIGHTSTATUS_FLIGHTMODE_POSITIONHOLD;
103 LoiterCommandData loiterCommand;
104 loiterCommand.Pitch = 0;
105 loiterCommand.Roll = 0;
106 loiterCommand.Thrust = 0.5f;
107 loiterCommand.Frame = LOITERCOMMAND_FRAME_BODY;
108 LoiterCommandSet(&loiterCommand);
111 case TABLETINFO_TABLETMODEDESIRED_RETURNTOHOME:
114 mode = FLIGHTSTATUS_FLIGHTMODE_RETURNTOHOME;
117 case TABLETINFO_TABLETMODEDESIRED_RETURNTOTABLET:
121 mode = FLIGHTSTATUS_FLIGHTMODE_TABLETCONTROL;
124 pathDesired.End[0] = NED[0];
125 pathDesired.End[1] = NED[1];
127 pathDesired.Mode = PATHDESIRED_MODE_HOLDPOSITION;
128 pathDesired.StartingVelocity = 5;
129 pathDesired.EndingVelocity = 5;
131 PathDesiredSet(&pathDesired);
135 case TABLETINFO_TABLETMODEDESIRED_PATHPLANNER:
136 mode = FLIGHTSTATUS_FLIGHTMODE_PATHPLANNER;
138 case TABLETINFO_TABLETMODEDESIRED_FOLLOWME:
140 mode = FLIGHTSTATUS_FLIGHTMODE_TABLETCONTROL;
147 PositionActualData positionActual;
148 PositionActualGet(&positionActual);
150 float DeltaN = NED[0] - positionActual.North;
151 float DeltaE = NED[1] - positionActual.East;
152 float dist = sqrtf(DeltaN * DeltaN + DeltaE * DeltaE);
158 pathDesired.End[0] = positionActual.North + frac * DeltaN;
159 pathDesired.End[1] = positionActual.East + frac * DeltaE;
162 pathDesired.End[0] = positionActual.North;
163 pathDesired.End[1] = positionActual.East;
166 pathDesired.Mode = FLIGHTSTATUS_FLIGHTMODE_PATHPLANNER;
167 pathDesired.StartingVelocity = 5;
168 pathDesired.EndingVelocity = 5;
170 PathDesiredSet(&pathDesired);
173 case TABLETINFO_TABLETMODEDESIRED_LAND:
175 AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_ERROR);
182 if (mode != flightStatus.FlightMode) {
184 flightStatus.FlightMode =
mode;
185 FlightStatusSet(&flightStatus);
202 HomeLocationGet(&homeLocation);
204 GPSPositionData gpsPosition;
205 GPSPositionGet(&gpsPosition);
207 float lat = homeLocation.Latitude / 10.0e6f * DEG2RAD;
208 float alt = homeLocation.Altitude;
211 T[0] = alt+6.378137E6f;
212 T[1] = cosf(lat)*(alt+6.378137E6f);
222 float dL[3] = {(tabletInfo->Latitude - homeLocation.Latitude) / 10.0e6f * DEG2RAD,
223 (tabletInfo->Longitude - homeLocation.Longitude) / 10.0e6f * DEG2RAD,
224 (tabletInfo->Altitude + gpsPosition.GeoidSeparation - homeLocation.Altitude)};
226 NED[0] = T[0] * dL[0];
227 NED[1] = T[1] * dL[1];
228 NED[2] = T[2] * dL[2];
Use tablet for control source.
static PathDesiredData pathDesired
Process transmitter inputs and use as control source.
int32_t tablet_control_update()
Process updates for the tablet controller.
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
static float T[3]
Scales used in NED transform (local tangent plane approx).
static HomeLocationData homeLocation
int32_t tablet_control_initialize()
Initialize the tablet controller.
Includes PiOS and core architecture components.
#define HOME_ALTITUDE_OFFSET
Private constants.
static int32_t tabletInfo_to_ned(TabletInfoData *tabletInfo, float *NED)
Private methods.
int32_t tablet_control_select(bool reset_controller)
Use the values for the tablet controller.