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
orange_avoider.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Roland Meertens
3  *
4  * This file is part of paparazzi
5  *
6  */
16 #include "state.h"
17 #include <time.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 
24 
26 {
27  // Initialise the variables of the colorfilter to accept orange
28  color_lum_min = 0;
29  color_lum_max = 131;
30  color_cb_min = 93;
31  color_cb_max = 255;
32  color_cr_min = 134;
33  color_cr_max = 255;
34  // Initialise random values
35  srand(time(NULL));
37 }
39 {
40  // Check the amount of orange. If this is above a threshold
41  // you want to turn a certain amount of degrees
43  printf("Checking if this function is called %d threshold: %d now: %d \n", color_count, tresholdColorCount,
45 }
46 
47 
52 {
53  *heading = *heading + increment;
54  // Check if your turn made it go out of bounds...
55  INT32_ANGLE_NORMALIZE(*heading); // HEADING HAS INT32_ANGLE_FRAC....
56  return false;
57 }
58 uint8_t moveWaypointForwards(uint8_t waypoint, float distanceMeters)
59 {
60  struct EnuCoor_i new_coor;
61  struct EnuCoor_i *pos = stateGetPositionEnu_i(); // Get your current position
62 
63  // Calculate the sine and cosine of the heading the drone is keeping
64  float sin_heading = sinf(ANGLE_FLOAT_OF_BFP(nav_heading));
65  float cos_heading = cosf(ANGLE_FLOAT_OF_BFP(nav_heading));
66 
67  // Now determine where to place the waypoint you want to go to
68  new_coor.x = pos->x + POS_BFP_OF_REAL(sin_heading * (distanceMeters));
69  new_coor.y = pos->y + POS_BFP_OF_REAL(cos_heading * (distanceMeters));
70  new_coor.z = pos->z; // Keep the height the same
71 
72  // Set the waypoint to the calculated position
73  waypoint_set_xy_i(waypoint, new_coor.x, new_coor.y);
74 
75  return false;
76 }
77 
79 {
80 
81  int r = rand() % 2;
82  if (r == 0) {
84  } else {
85  incrementForAvoidance = -350;
86  }
87  return false;
88 }
89 
int tresholdColorCount
void orange_avoider_init()
uint8_t safeToGoForwards
uint8_t moveWaypointForwards(uint8_t waypoint, float distanceMeters)
int32_t y
North.
int32_t x
East.
uint8_t color_cb_max
Definition: colorfilter.c:38
#define POS_BFP_OF_REAL(_af)
uint8_t color_lum_max
Definition: colorfilter.c:36
uint8_t increase_nav_heading(int32_t *heading, int32_t increment)
Increases the NAV heading.
uint8_t chooseRandomIncrementAvoidance()
int32_t incrementForAvoidance
#define ANGLE_FLOAT_OF_BFP(_ai)
void waypoint_set_xy_i(uint8_t wp_id, int32_t x, int32_t y)
Set only local XY coordinates of waypoint without update altitude.
Definition: waypoints.c:138
int color_count
Definition: colorfilter.c:43
static float heading
Definition: ahrs_infrared.c:45
uint8_t color_cr_max
Definition: colorfilter.c:40
#define INT32_ANGLE_NORMALIZE(_a)
uint8_t color_cb_min
Definition: colorfilter.c:37
int32_t z
Up.
signed long int32_t
Definition: types.h:19
vector in East North Up coordinates
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
void orange_avoider_periodic()
uint8_t color_lum_min
Definition: colorfilter.c:35
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
Definition: state.h:668
uint8_t color_cr_min
Definition: colorfilter.c:39