From 75fe3bee8c349c3db2e49385e607788422894ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Dvo=C5=99=C3=A1k?= Date: Sat, 25 Apr 2020 15:10:11 +0200 Subject: [PATCH] drivers/rpm: add simple RPM message simulator (dummy publisher) --- boards/px4/sitl/default.cmake | 1 + src/drivers/rpm/rpm_simulator/CMakeLists.txt | 39 ++++++++++ .../rpm/rpm_simulator/rpm_simulator.cpp | 78 +++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 src/drivers/rpm/rpm_simulator/CMakeLists.txt create mode 100644 src/drivers/rpm/rpm_simulator/rpm_simulator.cpp diff --git a/boards/px4/sitl/default.cmake b/boards/px4/sitl/default.cmake index d7480506d11d..6851856df3be 100644 --- a/boards/px4/sitl/default.cmake +++ b/boards/px4/sitl/default.cmake @@ -16,6 +16,7 @@ px4_add_board( #imu # all available imu drivers #magnetometer # all available magnetometer drivers pwm_out_sim + rpm/rpm_simulator #telemetry # all available telemetry drivers tone_alarm #uavcan diff --git a/src/drivers/rpm/rpm_simulator/CMakeLists.txt b/src/drivers/rpm/rpm_simulator/CMakeLists.txt new file mode 100644 index 000000000000..0cf7ad37dbd4 --- /dev/null +++ b/src/drivers/rpm/rpm_simulator/CMakeLists.txt @@ -0,0 +1,39 @@ +############################################################################ +# +# Copyright (c) 2020 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ +px4_add_module( + MODULE examples__rpm_simulator + MAIN rpm_simulator + SRCS + rpm_simulator.cpp + DEPENDS + ) diff --git a/src/drivers/rpm/rpm_simulator/rpm_simulator.cpp b/src/drivers/rpm/rpm_simulator/rpm_simulator.cpp new file mode 100644 index 000000000000..6253f6e4d354 --- /dev/null +++ b/src/drivers/rpm/rpm_simulator/rpm_simulator.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** + * + * Copyright (c) 2020 PX4 Development Team. All rights reserved. + * Copyright (c) 2020 ThunderFly s.r.o. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * @file rpm_simulator.c + * Simple app for publishing RPM messages with custom value. + * + * Usage: rpm_simulator + * rpm_simulator 344.2 + * + * @author ThunderFly s.r.o., Roman Dvorak + */ + +#include +#include + +#include +#include + +extern "C" __EXPORT int rpm_simulator_main(int argc, char *argv[]); +int rpm_simulator_main(int argc, char *argv[]) +{ + + // check input + if (argc != 2) { + PX4_INFO("Usage: rpm_simulator "); + PX4_INFO("Exit. Without publishing any message."); + return 0; + } + + rpm_s rpm{}; + + uORB::Publication rpm_pub{ORB_ID(rpm)}; + uint64_t timestamp_us = hrt_absolute_time(); + float frequency = atof(argv[1]); + + // prpepare RPM data message + rpm.timestamp = timestamp_us; + rpm.indicated_frequency_rpm = frequency; + rpm.estimated_accurancy_rpm = frequency / 100.0f; + + // Publish data and let the user know what was published + rpm_pub.publish(rpm); + print_message(rpm); + + return 0; +}