Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
follow_me.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Roland
3  *
4  * This file is part of paparazzi
5  *
6  */
17 #include "state.h"
18 #include "navigation.h"
20 #include "generated/flight_plan.h"
21 
22 #ifndef STEREOCAM_FOLLOW_ME_USE_OPTITRACK
23 #define STEREOCAM_FOLLOW_ME_USE_OPTITRACK FALSE
24 #endif
25 
26 
27 #define HEADING_CHANGE_PER_MEASUREMENT 260
28 #define CENTER_IMAGE_HOR 65
29 #define MAXIMUM_ALTITUDE_FOLLOWING 3.0
30 #define MINIMUM_ALTITUDE_FOLLOWING 1.0
31 float ref_pitch = 0.0;
32 float ref_roll = 0.0;
33 float selfie_alt = 1.0;
34 int breaksPoints = 0;
35 int isRollPhase = 0;
36 int isYawPhase = 0;
37 int phaseCounter = 0;
38 float heightGain = 0.3;
43 
44 void changeRollYawPhase(int *phaseCounterArg, int *isRollPhaseArg, int *isYawPhaseArg);
45 void changeRollYawPhase(int *phaseCounterArg, int *isRollPhaseArg, int *isYawPhaseArg)
46 {
47  (*phaseCounterArg)++;
48 
49  if (*isRollPhaseArg) {
50  if (*phaseCounterArg > amountOfRollPhaseTime) {
51  *phaseCounterArg = 0;
52  *isRollPhaseArg = 0;
53  *isYawPhaseArg = 1;
54  }
55  } else {
56  if (*phaseCounterArg > amountOfYawPhaseTime) {
57  *phaseCounterArg = 0;
58  *isRollPhaseArg = 1;
59  *isYawPhaseArg = 0;
60  }
61  }
62 }
63 
66 {
67  *heading = *heading + increment;
68 }
70 {
71  if (stereocam_data.fresh) {
73  if (stereocam_data.data[0] == 0 || stereocam_data.data[1] == 85 || stereocam_data.data[2] == 0) {
74  return;
75  }
76 
77  // If we don't use GPS we alternate a phase where we roll and where we yaw.
78  // This way we don't drift sideways AND we don't lose the user out of our sight
80  uint8_t headingToFollow = stereocam_data.data[0];
83 
84 
85  // Change our heading if the user is starting to get out of sight.
86  float heading_change = 0.0;
87  int headingChangePerIt = HEADING_CHANGE_PER_MEASUREMENT;
88  if (abs(headingToFollow - CENTER_IMAGE_HOR) > 10) {
89  if (headingToFollow > CENTER_IMAGE_HOR) {
90  heading_change = 0.25;
92  increase_nav_heading(&nav_heading, headingChangePerIt);
93  }
94  } else if (headingToFollow < CENTER_IMAGE_HOR) {
95  heading_change = -0.25;
97  increase_nav_heading(&nav_heading, -1 * headingChangePerIt);
98  }
99  } else {
100  heading_change = 0.0;
101  }
102 
103  } else {
104  heading_change = 0.0;
105  }
106 
107  // If we have our roll phase we take the value of the change we need to have in heading and use it to go sideways
108  ref_roll = 0.0;
109  if (isRollPhase) {
110  ref_roll = 30 * heading_change;
111  }
112 
113 
114  // If we are in flight we want to adjust our height based on the place where we see our object
115  if (nav_is_in_flight()) {
116  if (heightObject > 50) {
118  } else if (heightObject < 20) {
120  }
121  }
122 
123  // Bound the altitude to normal values
126  }
129  }
130 
131  // If using GPS we set the location of the waypoint to our desired altitude
132 #if STEREOCAM_FOLLOW_ME_USE_OPTITRACK
133  waypoint_set_alt(WP_STDBY, selfie_alt);
134 #endif
135 
136  // Set a pitch if the person we follow is too close
137  if (distanceToObject < 35) {
138  ref_pitch = 13.0;
139  } else if (distanceToObject < 60) {
140  ref_pitch = 5.0;
141  } else {
142  ref_pitch = -2.0;
143  }
144  }
145 }
int amountOfRollPhaseTime
Definition: follow_me.c:39
#define MINIMUM_ALTITUDE_FOLLOWING
Definition: follow_me.c:30
Periodic telemetry system header (includes downlink utility and generated code).
int amountOfYawPhaseTime
Definition: follow_me.c:40
uint8_t fresh
Definition: stereocam.h:35
#define CENTER_IMAGE_HOR
Definition: follow_me.c:28
void increase_nav_heading(int32_t *heading, int32_t increment)
Increases the NAV heading.
Definition: follow_me.c:65
float ref_pitch
Definition: follow_me.c:31
void waypoint_set_alt(uint8_t wp_id, float alt)
Set altitude of waypoint in meters (above reference)
Definition: waypoints.c:160
#define HEADING_CHANGE_PER_MEASUREMENT
Definition: follow_me.c:27
static float heading
Definition: ahrs_infrared.c:45
float heightGain
Definition: follow_me.c:38
interface to the TU Delft serial stereocam
void follow_me_periodic()
Definition: follow_me.c:69
uint8array stereocam_data
Definition: stereocam.c:57
uint8_t heightObject
Definition: follow_me.c:42
signed long int32_t
Definition: types.h:19
void changeRollYawPhase(int *phaseCounterArg, int *isRollPhaseArg, int *isYawPhaseArg)
Definition: follow_me.c:45
#define MAXIMUM_ALTITUDE_FOLLOWING
Definition: follow_me.c:29
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
int breaksPoints
Definition: follow_me.c:34
int isRollPhase
Definition: follow_me.c:35
float selfie_alt
Definition: follow_me.c:33
int isYawPhase
Definition: follow_me.c:36
#define STEREOCAM_FOLLOW_ME_USE_OPTITRACK
Definition: follow_me.c:23
int phaseCounter
Definition: follow_me.c:37
uint8_t * data
Definition: stereocam.h:34
uint8_t distanceToObject
Definition: follow_me.c:41
float ref_roll
Definition: follow_me.c:32