NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ninja.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdio.h>
4 
5 #include "sensors/instruments.h"
6 #include "flight/mixer.h"
7 #include "sensors/battery.h"
8 #include "system_calls.h"
9 #include "flight/anglerate.h"
10 #include "ninja_sched.h"
11 #include "blackbox/blackbox.h"
12 #include "io/rc_adjustments.h"
13 #include "flight/failsafe.h"
14 #include "io/ledstrip.h"
15 #include "io/beeper.h"
16 #include "io/serial_msp.h"
17 #include "msp.h"
18 #include "cli.h"
19 #include "sensors/gps.h"
20 #include "rx/rc.h"
21 
22 #include "common/pt.h"
23 
24 struct ninja;
25 
26 typedef enum {
27  NINJA_SENSOR_GYRO = (1 << 0),
28  NINJA_SENSOR_ACC = (1 << 1),
29  NINJA_SENSOR_MAG = (1 << 2),
30  NINJA_SENSOR_GPS = (1 << 3),
31  NINJA_SENSOR_BARO = (1 << 4),
32  NINJA_SENSOR_SONAR = (1 << 5)
34 
36  int16_t raw[8];
37 };
38 
39 struct ninja_state;
40 struct ninja {
41  struct instruments ins;
42  struct mixer mixer;
43  struct anglerate ctrl;
44  struct battery bat;
46  struct rc rc;
48  struct rx rx;
49  struct rc_adj rc_adj;
52  struct beeper beeper;
53  struct cli cli;
54  struct gps gps;
56  struct msp msp;
57 
59 
60  int16_t magHold;
62 
64 
65  int16_t telemTemperature1; // gyro sensor temperature
66  uint32_t disarmAt; // Time of automatic disarm when "Don't spin the motors when armed" is enabled and auto_disarm_delay is nonzero
67 
69  uint16_t cycleTime;
70 
72 
73  struct pt state_ctrl;
74 
75  struct pt state_arming;
78 
79  bool is_armed;
80  uint32_t sensors;
81 
83 
85 
88 
89  //uint8_t armingFlags;
90  //uint8_t stateFlags;
91  //uint16_t flightModeFlags;
92  //uint32_t enabledSensors;
93 
94  const struct system_calls *system;
95 
97  struct config *config;
98 };
99 
100 void ninja_init(struct ninja *self, const struct system_calls *syscalls, struct config *config);
101 
102 void ninja_arm(struct ninja *self);
103 void ninja_disarm(struct ninja *self);
104 
105 uint32_t ninja_has_sensors(struct ninja *self, sensor_mask_t sensor_mask);
106 bool ninja_is_armed(struct ninja *self);
107 
108 void ninja_heartbeat(struct ninja *self);
109 void ninja_input_rc(struct ninja *self, const struct ninja_rc_input *rc);
110 void ninja_input_gyro(struct ninja *self, int32_t x, int32_t y, int32_t z);
111 void ninja_input_acc(struct ninja *self, int32_t x, int32_t y, int32_t z);
112 
113 void ninja_run_pid_loop(struct ninja *self, uint32_t dt_us);
bool ninja_is_armed(struct ninja *self)
Definition: ninja.c:320
void ninja_input_acc(struct ninja *self, int32_t x, int32_t y, int32_t z)
sensor_mask_t
Definition: ninja.h:26
Definition: config.h:81
bool isRXDataNew
Definition: ninja.h:58
Definition: gps.h:69
Definition: ninja.h:40
int16_t raw[8]
Definition: ninja.h:36
Definition: ninja.h:27
struct instruments ins
Definition: ninja.h:41
void ninja_run_pid_loop(struct ninja *self, uint32_t dt_us)
Definition: ninja.c:652
Definition: cli.h:24
int16_t telemTemperature1
Definition: ninja.h:65
Definition: ninja.h:32
Definition: failsafe.h:46
uint32_t ninja_has_sensors(struct ninja *self, sensor_mask_t sensor_mask)
Definition: ninja.c:316
uint16_t cycleTime
Definition: ninja.h:69
Definition: ninja.h:30
Definition: serial_msp.h:87
struct pt state_arming
Definition: ninja.h:75
Definition: battery.h:30
Definition: beeper.h:69
uint16_t filteredCycleTime
Definition: ninja.h:68
Definition: ninja_sched.h:88
Definition: rc_adjustments.h:116
int16_t headFreeModeHold
Definition: ninja.h:61
bool is_armed
Definition: ninja.h:79
Definition: rx.h:97
int32_t sys_millis_t
Definition: system_calls.h:6
sys_micros_t loop_time
Definition: ninja.h:82
uint32_t sensors
Definition: ninja.h:80
void ninja_disarm(struct ninja *self)
Definition: ninja.c:212
void ninja_arm(struct ninja *self)
Definition: ninja.c:205
uint8_t motorControlEnable
Definition: ninja.h:63
Definition: ninja.h:35
void ninja_input_rc(struct ninja *self, const struct ninja_rc_input *rc)
Definition: rc.h:91
void ninja_heartbeat(struct ninja *self)
Definition: ninja.c:679
Definition: rc.h:78
Definition: mixer.h:159
int32_t sys_micros_t
Definition: system_calls.h:7
uint16_t direct_outputs[MIXER_OUTPUT_COUNT]
this is used for directly controlling motors while we are disarmed (from gcs)
Definition: ninja.h:87
sys_millis_t disarm_timeout
Definition: ninja.h:77
Definition: ninja.h:31
sys_millis_t arming_delay
Definition: ninja.h:76
uint8_t z
set the acc deadband for z-Axis, this ignores small accelerations
Definition: accelerometer.h:52
void ninja_input_gyro(struct ninja *self, int32_t x, int32_t y, int32_t z)
Definition: msp.h:28
uint32_t disarmAt
Definition: ninja.h:66
Definition: blackbox.h:90
const struct system_calls * system
Definition: ninja.h:94
Definition: pt.h:99
struct config * config
pointer to current configuration
Definition: ninja.h:97
Definition: system_calls.h:200
struct ninja_rc_input rc_input
Definition: ninja.h:71
Definition: ninja.h:29
struct pt state_ctrl
Definition: ninja.h:73
void ninja_init(struct ninja *self, const struct system_calls *syscalls, struct config *config)
Definition: ninja.c:83
Definition: ninja.h:28
struct ninja_sched sched
Definition: ninja.h:84
struct battery bat
Definition: ninja.h:44
struct anglerate ctrl
Definition: ninja.h:43
int16_t magHold
Definition: ninja.h:60
Definition: mixer.h:55
Definition: instruments.h:11
Definition: ledstrip.h:30
Definition: anglerate.h:48
struct rc_event_listener rc_evl
Definition: ninja.h:47