45 #include <px4_platform_common/tasks.h> 46 #include <px4_platform_common/getopt.h> 47 #include <px4_platform_common/posix.h> 63 #include <bebop_bus/BebopBus.hpp> 95 int set_esc_speeds(
const float speed_scaled[4]);
111 const uint8_t _esc_map[4] = {0, 2, 3, 1};
113 int _publish(
struct bebop_state_data &
data);
117 BebopBus(BEBOP_BUS_DEVICE_PATH), _battery_topic(nullptr), _esc_topic(nullptr), _battery(),
_armed(false),
118 _last_throttle(0.0
f),
119 _battery_orb_class_instance(-1)
128 PX4_ERR(
"BebopBus init fail: %d", ret);
135 PX4_ERR(
"BebopBus start fail: %d", ret);
151 PX4_ERR(
"BebopBus stop fail: %d", ret);
161 int ret = _get_info(&info);
167 PX4_INFO(
"Bebop Controller Info");
168 PX4_INFO(
" Software Version: %d.%d", info.version_major, info.version_minor);
169 PX4_INFO(
" Software Type: %d", info.type);
170 PX4_INFO(
" Number of controlled motors: %d", info.n_motors_controlled);
171 PX4_INFO(
" Number of flights: %d", info.n_flights);
172 PX4_INFO(
" Last flight time: %d", info.last_flight_time);
173 PX4_INFO(
" Total flight time: %d", info.total_flight_time);
174 PX4_INFO(
" Last Error: %d\n", info.last_error);
182 return BebopBus::_start_motors();
188 return BebopBus::_stop_motors();
193 return BebopBus::_clear_errors();
198 return BebopBus::_set_esc_speed(speed_scaled);
214 uint16_t esc_speed_setpoint_rpm[4] = {};
215 BebopBus::_get_esc_speed_setpoint(esc_speed_setpoint_rpm);
219 for (
int i = 0; i < 4; i++) {
225 if (!(m_pub_blocked)) {
283 uint8_t control_index,
float &input);
286 uint8_t control_group,
287 uint8_t control_index,
292 input = controls[control_group].
control[control_index];
299 char buf[2048] = {0};
300 size_t buflen =
sizeof(buf);
302 PX4_INFO(
"Trying to initialize mixers from config file %s", mixers_filename);
305 PX4_ERR(
"can't load mixer: %s", mixers_filename);
309 if (_mixers ==
nullptr) {
313 if (_mixers ==
nullptr) {
314 PX4_ERR(
"No mixers available");
321 PX4_ERR(
"Unable to parse mixers file");
340 _armed.
armed =
false;
342 _motors_running =
false;
345 px4_pollfd_struct_t fds[1];
347 fds[0].events = POLLIN;
353 PX4_ERR(
"Mixer initialization failed.");
358 while (!_task_should_exit) {
360 int pret =
px4_poll(&fds[0], (
sizeof(fds) /
sizeof(fds[0])), 10);
369 PX4_WARN(
"poll error %d, %d", pret, errno);
375 if (fds[0].revents & POLLIN) {
376 orb_copy(
ORB_ID(actuator_controls_0), _controls_sub, &_controls[0]);
381 if (_mixers !=
nullptr) {
396 for (
size_t i = 0; i < _outputs.
noutputs; ++i) {
398 PX4_ISFINITE(_outputs.
output[i]) &&
399 _outputs.
output[i] >= -1.0f &&
400 _outputs.
output[i] <= 1.0f) {
416 motor_out[0] = _outputs.
output[2];
417 motor_out[1] = _outputs.
output[0];
418 motor_out[2] = _outputs.
output[3];
419 motor_out[3] = _outputs.
output[1];
423 if (_outputs_pub !=
nullptr) {
441 if (_armed.
armed && !lockdown && !_motors_running) {
443 _motors_running =
true;
447 if ((!_armed.
armed || lockdown) && _motors_running) {
449 _motors_running =
false;
464 if (g_dev ==
nullptr) {
465 PX4_ERR(
"failed instantiating DfBebopBusWrapper object");
469 int ret = g_dev->
start();
472 PX4_ERR(
"DfBebopBusWrapper start failed");
478 DevMgr::getHandle(BEBOP_BUS_DEVICE_PATH, h);
481 DF_LOG_INFO(
"Error: unable to obtain a valid handle for the receiver at: %s (%d)",
482 BEBOP_BUS_DEVICE_PATH, h.getError());
486 DevMgr::releaseHandle(h);
489 _task_handle = px4_task_spawn_cmd(
"bebop_bus_esc_main",
496 if (_task_handle < 0) {
497 PX4_ERR(
"task start failed");
508 _task_should_exit =
true;
510 while (_is_running) {
517 if (g_dev ==
nullptr) {
518 PX4_ERR(
"driver not running");
523 int ret = g_dev->
stop();
526 PX4_ERR(
"driver could not be stopped");
541 if (g_dev ==
nullptr) {
542 PX4_ERR(
"driver not running");
546 PX4_DEBUG(
"state @ %p", g_dev);
551 PX4_ERR(
"Unable to print info");
564 if (g_dev ==
nullptr) {
565 PX4_ERR(
"driver not running");
569 PX4_DEBUG(
"state @ %p", g_dev);
574 PX4_ERR(
"Unable to clear errors");
584 PX4_INFO(
"Usage: df_bebop_bus_wrapper 'start', 'info', 'clear_errors', 'stop'");
601 const char *verb = argv[myoptind];
604 if (!strcmp(verb,
"start")) {
608 else if (!strcmp(verb,
"stop")) {
612 else if (!strcmp(verb,
"info")) {
616 else if (!strcmp(verb,
"clear_errors")) {
volatile bool _task_should_exit
int load_from_buf(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen)
Adds mixers to the group based on a text description in a buffer.
int start()
Attempt to start driver on all available I2C busses.
int set_esc_speeds(const float speed_scaled[4])
Set the ESC speeds [front left, front right, back right, back left].
struct esc_report_s esc[8]
int initialize_mixers(const char *mixers_filename)
static const char * MIXER_FILENAME
int orb_copy(const struct orb_metadata *meta, int handle, void *buffer)
DfBebopBusWrapper * g_dev
void usage()
Prints info about the driver argument usage.
int info()
Print a little info about the driver.
actuator_controls_s _controls[1]
int stop()
Stop the driver.
int clear_errors()
Clear errors present on the Bebop hardware.
void usage(const char *reason)
Print the correct usage.
int clear_errors()
Reset pending errors on the Bebop hardware.
int start()
Start and initialize the driver.
static px4_task_t _task_handle
orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data)
__EXPORT int df_bebop_bus_wrapper_main(int argc, char *argv[])
int _battery_orb_class_instance
Library calls for battery functionality.
int start_motors()
Start the motors.
int _publish(struct bebop_state_data &data)
int orb_subscribe(const struct orb_metadata *meta)
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
void init()
Activates/configures the hardware registers.
int orb_unsubscribe(int handle)
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
void set_last_throttle(float throttle)
Capture the last throttle value for the battey computation.
int print_info()
Print various infos (version, type, flights, errors.
int stop_motors()
Stop the motors.
void task_main(int argc, char *argv[])
int load_mixer_file(const char *fname, char *buf, unsigned maxlen)
int stop()
Stop the driver.
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data)
void updateBatteryStatus(hrt_abstime timestamp, float voltage_v, float current_a, bool connected, bool selected_source, int priority, float throttle_normalized, bool armed, battery_status_s *status)
Update current battery status message.
const uint8_t _esc_map[4]
int orb_check(int handle, bool *updated)
orb_advert_t _battery_topic
actuator_outputs_s _outputs
unsigned mix(float *outputs, unsigned space)
int mixers_control_callback(uintptr_t handle, uint8_t control_group, uint8_t control_index, float &input)
static bool _motors_running
Group of mixers, built up from single mixers and processed in order when mixing.
orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance, int priority)
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
orb_advert_t _outputs_pub