14 const double &timeout,
const bool print_info) {
20 if(print_info) std::cout << fcvar;
26 if(print_info) std::cout << api_version;
41 if(print_info) std::cout << boardinfo;
52 if(print_info) std::cout << status;
57 if(print_info) std::cout << ident;
74 if(print_info) std::cout << rx_map;
104 std::cout <<
"client_.sendMessage(rxConfig) failed" << std::endl;
105 std::cout << rxConfig;
109 static_cast<msp::msg::RxConfigSettings &>(rxConfig);
143 std::vector<uint16_t> cmds(6, 1000);
148 cmds[0] = uint16_t(
rpyt_[3] * 500) + 1500;
149 cmds[1] = uint16_t(
rpyt_[0] * 500) + 1500;
150 cmds[2] = uint16_t(
rpyt_[1] * 500) + 1500;
151 cmds[3] = uint16_t(
rpyt_[2] * 500) + 1500;
201 throw std::runtime_error(
"Cannot get BoxNames!");
206 throw std::runtime_error(
"Cannot get BoxIds!");
210 for(
size_t ibox(0); ibox < box_names.
box_names.size(); ibox++) {
224 const double &timeout) {
228 throw std::runtime_error(
229 "Box ID of " + status_name +
230 " is unknown! You need to call 'initBoxes()' first.");
241 const uint16_t yaw,
const uint16_t throttle,
242 const uint16_t aux1,
const uint16_t aux2,
243 const uint16_t aux3,
const uint16_t aux4,
244 const std::vector<uint16_t> auxs) {
259 rc.
channels.insert(std::end(rc.
channels), std::begin(auxs), std::end(auxs));
272 const std::array<uint16_t, msp::msg::N_MOTOR> &motor_values) {
274 motor.
motor = motor_values;
279 const std::set<std::string> &
remove) {
288 for(
const std::string &a : add) {
292 for(
const std::string &rem :
remove) {
msp::FirmwareVariant fw_variant_
bool start(const std::string &device, const size_t baudrate=115200)
Start communications with a flight controller.
Value< uint8_t > serialrx_provider
int updateFeatures(const std::set< std::string > &add=std::set< std::string >(), const std::set< std::string > &remove=std::set< std::string >())
Enable and disable features on the FC To apply updates, changes will be written to the EEPROM and the...
ControlSource control_source_
Value< std::string > identifier
bool sendMessageNoWait(const msp::Message &message)
Send a message, but do not wait for any response.
std::array< uint8_t, msp::msg::MAX_MAPPABLE_RX_INPUTS > channel_map_
std::array< uint16_t, N_MOTOR > motor
bool disconnect()
Stops MSP control if active, and disconnects the internal Client object.
bool setVersion(const int &ver)
Change the device path on the next connect.
bool saveSettings()
Sends message to flight controller to save all settings.
std::set< msp::msg::Capability > capabilities_
std::set< std::string > features
void setLoggingLevel(const LoggingLevel &level)
Set the verbosity of the output.
msp::client::Client client_
std::array< double, 4 > rpyt_
bool stop()
Stop communications with a flight controller.
static const std::map< std::string, FirmwareVariant > variant_map
std::vector< uint16_t > channels
void initBoxes()
Queries the flight controller for Box (flight mode) information.
FirmwareVariant
Enum of firmware variants.
ControlSource getControlSource()
Queries the currently active control source.
FlightController()
FlightController Constructor.
void setRPYT(std::array< double, 4 > &&rpyt)
Sets roll, pitch, yaw, and throttle values. They are sent immediately and stored for resending if aut...
bool isConnected() const
Tests connection to a flight controller.
void setFlightMode(const FlightMode mode)
Sets data structure with all flags governing flight mode.
Value< uint8_t > receiverType
void setControlSource(const ControlSource source)
Sets which instruction source the flight controller should listen to. Also starts periodic MSP contro...
std::vector< std::string > box_names
~FlightController()
~FlightController Destructor
std::set< std::string > features
void setLoggingLevel(const msp::client::LoggingLevel &level)
Set the verbosity of the output.
static const size_t MAX_MAPPABLE_RX_INPUTS
FlightMode getFlightMode() const
Queries data structure with all flags governing flight mode.
bool setMotors(const std::array< uint16_t, msp::msg::N_MOTOR > &motor_values)
Directly sets motor values using SetMotor message.
std::set< msp::msg::Sensor > sensors_
std::set< size_t > box_mode_flags
std::string getBoardName() const
Queries the currently set board name.
bool setRc(const uint16_t roll, const uint16_t pitch, const uint16_t yaw, const uint16_t throttle, const uint16_t aux1=1000, const uint16_t aux2=1000, const uint16_t aux3=1000, const uint16_t aux4=1000, const std::vector< uint16_t > auxs=std::vector< uint16_t >())
Set RC channels in order: roll, pitch, yaw, throttle by using channel mapping.
bool sendMessage(msp::Message &message, const double &timeout=0)
Send a message to the connected flight controller. If the message sends data to the flight controller...
msp::FirmwareVariant getFwVariant() const
Queries the currently set firmware variant (Cleanflight, Betaflight, etc.)
void generateMSP()
Method used to generate the Rc message sent to the flight controller.
std::mutex msp_updates_mutex
bool reboot()
Starts message to flight controller signalling that it should reboot. Will result in the serial devic...
bool isConnected() const
Query the system to see if a connection is active.
bool set() const
Queries if the data has been set.
bool connect(const std::string &device, const size_t baudrate=115200, const double &timeout=0.0, const bool print_info=false)
Connects to a physical flight controller, which includes connecting the internal Client object and qu...
std::map< std::string, size_t > box_name_ids_
int getProtocolVersion() const
Queries the currently set protocol (MSPv1 or MSPv2)
bool isStatusActive(const std::string &status_name, const double &timeout=0)
Queries the flight controller to see if a status is active.