NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rc_command.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
27 #pragma once
28 
29 #include "config/rate_profile.h"
30 
32 #define PITCH_LOOKUP_LENGTH 7
33 #define YAW_LOOKUP_LENGTH 7
35 #define THROTTLE_LOOKUP_LENGTH 12
37 
39 struct rc_command {
40  int16_t roll, pitch, yaw, throttle;
41 
43  int16_t tpa;
44 
46  const struct rate_profile *config;
47 
51 
52  struct rx *rx;
53 };
54 
56 void rc_command_init(struct rc_command *self, struct rx *rx);
57 
59 void rc_command_set_rate_config(struct rc_command *self, const struct rate_profile *rates);
60 
62 void rc_command_update(struct rc_command *self);
63 
65 int16_t rc_command_axis(struct rc_command *self, uint8_t stick);
66 
68 static inline int16_t rc_command_throttle(struct rc_command *self) { return self->throttle; }
69 
71 static inline uint8_t rc_command_tpa(struct rc_command *self){ return self->tpa; } // TODO: tpa should probably not be here. This is just for now.
#define THROTTLE_LOOKUP_LENGTH
compile time configuration of the throttle lookup table
Definition: rc_command.h:36
int16_t tpa
Throttle PID Addjustment. TODO: this really does not belong in this class.
Definition: rc_command.h:43
#define YAW_LOOKUP_LENGTH
compile time configuration of the yaw lookup table
Definition: rc_command.h:34
void rc_command_set_rate_config(struct rc_command *self, const struct rate_profile *rates)
Updates internal variables to use new rates and also recalculates the lookup tables if the supplied p...
Definition: rc_command.c:166
struct rx * rx
Definition: rc_command.h:52
int16_t pitch
Definition: rc_command.h:40
void rc_command_update(struct rc_command *self)
Updates current rc rates from the current rc values. Inputs are in range [1000;2000] and should corre...
Definition: rc_command.c:117
#define PITCH_LOOKUP_LENGTH
compile time configuration of the pitch/roll lookup table
Definition: rc_command.h:32
int16_t lookup_yaw[YAW_LOOKUP_LENGTH]
lookup table for expo & RC rate YAW
Definition: rc_command.h:49
int16_t lookup_throttle[THROTTLE_LOOKUP_LENGTH]
lookup table for expo & mid THROTTLE
Definition: rc_command.h:50
RC commands state. Inputs are raw commands in range [1000-2000]. Outputs are RC commands in range [-5...
Definition: rc_command.h:39
int16_t throttle
Definition: rc_command.h:40
Definition: rx.h:97
int16_t roll
Definition: rc_command.h:40
uint8_t rates[3]
Definition: rate_profile.h:32
int16_t yaw
Definition: rc_command.h:40
Definition: rate_profile.h:26
int16_t lookup_roll_pitch[PITCH_LOOKUP_LENGTH]
lookup table for expo & RC rate PITCH+ROLL
Definition: rc_command.h:48
void rc_command_init(struct rc_command *self, struct rx *rx)
Initializes the curves with default linear ranges.
Definition: rc_command.c:98
const struct rate_profile * config
current rate config
Definition: rc_command.h:46
int16_t rc_command_axis(struct rc_command *self, uint8_t stick)
Get current stick value in range [-500;500], stick is only ROLL, PITCH, YAw.
Definition: rc_command.c:155