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
53 {
54  // Initialize the arming finite state machine
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
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
88 }
89 
90 
91 // Main loop
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
112 
113  // receive mavlink messages
115 
116  // update the state machine, an internal timer runs this at a fixed rate
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)
124 }
125 
127 {
128  return loop_time_us;
129 }
130 
131 }
ROSCPP_DECL void start()
void run()
Main loop for the ROSflight autopilot flight stack.
Definition: rosflight.cpp:92
virtual uint64_t clock_micros()=0
ROSflight(Board &board, CommLink &comm_link)
Definition: rosflight.cpp:37
void init()
Initialize parameter values.
Definition: param.cpp:90
void init()
Main initialization routine for the ROSflight autopilot flight stack.
Definition: rosflight.cpp:52


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:25