34 #include <px4_platform_common/getopt.h> 35 #include <px4_platform_common/tasks.h> 36 #include <px4_platform_common/log.h> 46 #include <semaphore.h> 47 #include "rc_receiver_api.h" 55 #define MAX_LEN_DEV_PATH 32 61 #define SIGNAL_LOST_THRESHOLD_MS 500 79 static uint16_t
rc_inputs[input_rc_s::RC_INPUT_MAX_CHANNELS];
107 static void task_main(
int argc,
char *argv[]);
117 PX4_DEBUG(
"rc_receiver_parameters_update");
122 _rc_receiver_type = (
enum RC_RECEIVER_TYPES)v;
123 PX4_DEBUG(
"rc_receiver_parameters_update rc_receiver_type %f", v);
150 ASSERT(_task_handle == -1);
153 _task_handle = px4_task_spawn_cmd(
"rc_receiver_main",
160 if (_task_handle < 0) {
161 warn(
"task start failed");
178 PX4_WARN(
"task_main_trampoline");
184 PX4_WARN(
"enter rc_receiver task_main");
192 if (_input_rc_pub ==
nullptr) {
193 PX4_WARN(
"failed to advertise input_rc uorb topic. Quit!");
201 fd = rc_receiver_open(_rc_receiver_type, _device);
204 PX4_WARN(
"failed to open rc receiver type %d dev %s. Quit!",
205 _rc_receiver_type, _device);
211 uint32_t num_channels;
218 while (!_task_should_exit) {
223 num_channels = input_rc_s::RC_INPUT_MAX_CHANNELS;
225 ret = rc_receiver_get_packet(fd, rc_inputs, &num_channels);
239 if (++counter == 500) {
240 PX4_WARN(
"RC signal lost for %u ms", time_diff_us / 1000);
263 for (uint32_t i = 0; i < num_channels; i++) {
269 _rc_in.
values[i] = ((((int)(rc_inputs[i] * 2) - 1024) * 1000) / 1700) + 1500;
275 rc_receiver_close(fd);
280 PX4_WARN(
"missing command: try 'start', 'stop', 'status'");
281 PX4_WARN(
"options:");
282 PX4_WARN(
" -D device");
289 const char *
device = NULL;
292 const char *myoptarg = NULL;
295 while ((ch = px4_getopt(argc, argv,
"D:", &myoptind, &myoptarg)) != EOF) {
308 if (device == NULL || strlen(device) == 0) {
316 const char *verb = argv[myoptind];
321 if (!strcmp(verb,
"start")) {
323 PX4_WARN(
"rc_receiver already running");
329 }
else if (!strcmp(verb,
"stop")) {
331 PX4_WARN(
"rc_receiver is not running");
337 }
else if (!strcmp(verb,
"status")) {
int orb_copy(const struct orb_metadata *meta, int handle, void *buffer)
#define SIGNAL_LOST_THRESHOLD_MS
Threshold value to detect rc receiver signal lost in millisecond.
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
static bool _is_running
flag indicating if rc_receiver module is running
__EXPORT int rc_receiver_main(int argc, char *argv[])
driver 'main' command
orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data)
static void task_main(int argc, char *argv[])
mpu9x50 measurement thread primary entry point
struct rc_receiver::@17 _params_handles
parameter handles
Namespace encapsulating all device framework classes, functions and data.
static void task_main_trampoline(int argc, char *argv[])
task main trampoline function
High-resolution timer with callouts and timekeeping.
int orb_subscribe(const struct orb_metadata *meta)
static char _device[MAX_LEN_DEV_PATH]
serial device path that rc receiver is connected to
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
static struct input_rc_s _rc_in
rc_input uorb topic data
static enum RC_RECEIVER_TYPES _rc_receiver_type
RC receiver type.
static uint16_t rc_inputs[input_rc_s::RC_INPUT_MAX_CHANNELS]
RC input channel value array accomondating up to RC_INPUT_MAX_CHANNELS.
static bool _task_should_exit
flag indicating if task thread should exit
static px4_task_t _task_handle
handle to the task main thread
static void stop()
mpu9x50 stop measurement
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
static orb_advert_t _input_rc_pub
rc_input uorb topic publication handle
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data)
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
int orb_check(int handle, bool *updated)
static void start()
mpu9x50 start measurement
static void parameters_update()
update all parameters
static void parameter_update_poll()
poll parameter update
static void usage()
Print out the usage information.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
uint32_t param_t
Parameter handle.