Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
firmware
src
rosflight.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017, James Jackson and Daniel Koch, BYU MAGICC Lab
3
*
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are met:
8
*
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
*
12
* * Redistributions in binary form must reproduce the above copyright notice,
13
* this list of conditions and the following disclaimer in the documentation
14
* and/or other materials provided with the distribution.
15
*
16
* * Neither the name of the copyright holder nor the names of its
17
* contributors may be used to endorse or promote products derived from
18
* this software without specific prior written permission.
19
*
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
#include "rosflight.h"
33
34
namespace
rosflight_firmware
35
{
36
37
ROSflight::ROSflight
(
Board
&board,
CommLink
&comm_link) :
38
board_(board),
39
comm_manager_(*this, comm_link),
40
params_(*this),
41
command_manager_(*this),
42
controller_(*this),
43
estimator_(*this),
44
mixer_(*this),
45
rc_(*this),
46
sensors_(*this),
47
state_manager_(*this)
48
{
49
}
50
51
// Initialization Routine
52
void
ROSflight::init
()
53
{
54
// Initialize the arming finite state machine
55
state_manager_
.
init
();
56
57
// Read EEPROM to get initial params
58
params_
.
init
();
59
60
// Initialize Mixer
61
mixer_
.
init
();
62
63
/***********************/
64
/*** Hardware Setup ***/
65
/***********************/
66
67
// Initialize PWM and RC
68
rc_
.
init
();
69
70
// Initialize MAVlink Communication
71
comm_manager_
.
init
();
72
73
// Initialize Sensors
74
sensors_
.
init
();
75
76
/***********************/
77
/*** Software Setup ***/
78
/***********************/
79
80
// Initialize Estimator
81
estimator_
.
init
();
82
83
// Initialize Controller
84
controller_
.
init
();
85
86
// Initialize the command muxer
87
command_manager_
.
init
();
88
}
89
90
91
// Main loop
92
void
ROSflight::run
()
93
{
94
/*********************/
95
/*** Control Loop ***/
96
/*********************/
97
uint64_t
start
=
board_
.
clock_micros
();
98
if
(
sensors_
.
run
())
99
{
100
// If I have new IMU data, then perform control
101
estimator_
.
run
();
102
controller_
.
run
();
103
mixer_
.
mix_output
();
104
loop_time_us
=
board_
.
clock_micros
() - start;
105
}
106
107
/*********************/
108
/*** Post-Process ***/
109
/*********************/
110
// internal timers figure out what and when to send
111
comm_manager_
.
stream
();
112
113
// receive mavlink messages
114
comm_manager_
.
receive
();
115
116
// update the state machine, an internal timer runs this at a fixed rate
117
state_manager_
.
run
();
118
119
// get RC, an internal timer runs this every 20 ms (50 Hz)
120
rc_
.
run
();
121
122
// update commands (internal logic tells whether or not we should do anything or not)
123
command_manager_
.
run
();
124
}
125
126
uint32_t
ROSflight::get_loop_time_us
()
127
{
128
return
loop_time_us
;
129
}
130
131
}
rosflight_firmware::ROSflight::loop_time_us
uint32_t loop_time_us
Definition:
include/rosflight.h:72
rosflight_firmware::ROSflight::estimator_
Estimator estimator_
Definition:
include/rosflight.h:66
rosflight_firmware::Controller::run
void run()
Definition:
controller.cpp:147
rosflight_firmware::StateManager::run
void run()
Definition:
state_manager.cpp:64
start
ROSCPP_DECL void start()
rosflight_firmware::Sensors::init
void init()
Definition:
sensors.cpp:62
rosflight_firmware::ROSflight::sensors_
Sensors sensors_
Definition:
include/rosflight.h:69
rosflight_firmware::Mixer::mix_output
void mix_output()
Definition:
mixer.cpp:166
rosflight_firmware
Definition:
airbourne_board.cpp:34
rosflight_firmware::CommManager::receive
void receive(void)
Definition:
comm_manager.cpp:373
rosflight_firmware::Controller::init
void init()
Definition:
controller.cpp:117
rosflight_firmware::Estimator::run
void run()
Definition:
estimator.cpp:121
rosflight_firmware::ROSflight::comm_manager_
CommManager comm_manager_
Definition:
include/rosflight.h:60
rosflight_firmware::CommLink
Definition:
comm_link.h:46
rosflight_firmware::ROSflight::get_loop_time_us
uint32_t get_loop_time_us()
Definition:
rosflight.cpp:126
rosflight_firmware::RC::run
bool run()
Definition:
rc.cpp:297
rosflight_firmware::CommManager::init
void init()
Definition:
comm_manager.cpp:49
rosflight_firmware::ROSflight::rc_
RC rc_
Definition:
include/rosflight.h:68
rosflight_firmware::ROSflight::run
void run()
Main loop for the ROSflight autopilot flight stack.
Definition:
rosflight.cpp:92
rosflight_firmware::ROSflight::mixer_
Mixer mixer_
Definition:
include/rosflight.h:67
rosflight_firmware::Mixer::init
void init()
Definition:
mixer.cpp:47
rosflight_firmware::Estimator::init
void init()
Definition:
estimator.cpp:92
rosflight_firmware::Board::clock_micros
virtual uint64_t clock_micros()=0
rosflight_firmware::CommandManager::init
void init()
Definition:
command_manager.cpp:72
rosflight_firmware::CommandManager::run
bool run()
Definition:
command_manager.cpp:270
rosflight_firmware::CommManager::stream
void stream()
Definition:
comm_manager.cpp:585
rosflight_firmware::ROSflight::ROSflight
ROSflight(Board &board, CommLink &comm_link)
Definition:
rosflight.cpp:37
rosflight_firmware::StateManager::init
void init()
Definition:
state_manager.cpp:47
rosflight_firmware::RC::init
void init()
Definition:
rc.cpp:45
rosflight_firmware::ROSflight::params_
Params params_
Definition:
include/rosflight.h:62
rosflight_firmware::Params::init
void init()
Initialize parameter values.
Definition:
param.cpp:90
rosflight_firmware::ROSflight::state_manager_
StateManager state_manager_
Definition:
include/rosflight.h:70
rosflight_firmware::ROSflight::command_manager_
CommandManager command_manager_
Definition:
include/rosflight.h:64
rosflight_firmware::Sensors::run
bool run()
Definition:
sensors.cpp:120
rosflight_firmware::ROSflight::init
void init()
Main initialization routine for the ROSflight autopilot flight stack.
Definition:
rosflight.cpp:52
rosflight_firmware::ROSflight::controller_
Controller controller_
Definition:
include/rosflight.h:65
rosflight_firmware::Board
Definition:
board.h:69
rosflight_firmware::ROSflight::board_
Board & board_
Definition:
include/rosflight.h:59
rosflight_firmware
Author(s): Daniel Koch
, James Jackson
autogenerated on Wed Jul 3 2019 19:59:25