-
Notifications
You must be signed in to change notification settings - Fork 2
/
cansat_navigation.ino
73 lines (60 loc) · 1.79 KB
/
cansat_navigation.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "src/cansat_navigation.h"
#include "src/cansat_Debug.h"
CansatNavigation cansatNavigation;
void setupNavigation(bool mode){
int offset_angle=-6;
cansatNavigation.begin(D0,winchCallback,offset_angle);
setNavigationMode(mode);
cansatNavigation.winchNeutral();
Serial.println(F("Navigation begin"));
}
void updateNavigation(){
float ground_alt=cansatLocation.getGroundAltitude();
//update navigation parameters
if(destination_locked){
cansatNavigation.updateNavigationParamers(location_distance,location_bearing,cansatGPS.ground_course(),ground_alt);
//update control angle
cansatNavigation.updateControlAngle();
// turn winch
/*
Serial.print(F("isAuto="));
Serial.println(isAutoMode());
Serial.print(F("GPS num="));
Serial.println(cansatGPS.status());
*/
if(isAutoMode()&& (cansatGPS.status()>=2)){ //GPS_FIX_TYPE_2D_FIX
cansatNavigation.winchControl(0); // ignore angle when auto mode
}
//send info to base station
Serial.print("%,6,2,"); // header,class,num data
Serial.print(cansatNavigation.getControlAngle());Serial.print(',');
Serial.println(ground_alt);
}
}
void timerRun(){
cansatNavigation.timerRun();
}
void winchCallback(){
cansatNavigation.winchNeutral();
CANSAT_LOG("winch callback");
}
void setNavigationMode(bool mode){
//mode 0 :audo
//mode 1 : manual
cansatNavigation.setNavigationMode(mode);
}
bool isAutoMode(){
return !(cansatNavigation.getNavigationMode());
}
void winchControl(float angle){
cansatNavigation.winchControl(angle);
}
uint32_t prev_time;
void testWinch(){
uint32_t t_now=millis();
if(t_now-prev_time>8000){
prev_time=t_now;
winchControl(50);
}
timerRun();
}