cmake remove circular linking and reorganize

- px4_add_module now requires MAIN
 - px4_add_library doesn't automatically link
This commit is contained in:
Daniel Agar
2018-04-11 15:10:51 -04:00
parent a8bc3d187f
commit ea3acb7121
576 changed files with 1406 additions and 2014 deletions
@@ -40,6 +40,5 @@ px4_add_module(
SRCS
attitude_estimator_q_main.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
@@ -48,8 +48,8 @@
#include <px4_posix.h>
#include <px4_tasks.h>
#include <systemlib/err.h>
#include <systemlib/param/param.h>
#include <systemlib/perf_counter.h>
#include <parameters/param.h>
#include <perf/perf_counter.h>
#include <uORB/topics/att_pos_mocap.h>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/sensor_combined.h>
@@ -39,7 +39,7 @@
* @author Anton Babushkin <anton.babushkin@me.com>
*/
#include <systemlib/param/param.h>
#include <parameters/param.h>
/**
* Complimentary filter accelerometer weight
+1 -2
View File
@@ -37,6 +37,5 @@ px4_add_module(
SRCS
camera_feedback.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
@@ -47,7 +47,7 @@
#include <mathlib/mathlib.h>
#include <systemlib/systemlib.h>
#include <systemlib/err.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <px4_config.h>
#include <px4_defines.h>
+1 -2
View File
@@ -52,6 +52,5 @@ px4_add_module(
PreflightCheck.cpp
arm_auth.cpp
DEPENDS
platforms__common
df_driver_framework
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -1
View File
@@ -52,7 +52,7 @@
#include <poll.h>
#include <systemlib/err.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/rc_check.h>
#include <systemlib/mavlink_log.h>
@@ -143,7 +143,7 @@
#include <drivers/drv_accel.h>
#include <lib/ecl/geo/geo.h>
#include <conversion/rotation.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/err.h>
#include <systemlib/mavlink_log.h>
#include <uORB/topics/vehicle_attitude.h>
@@ -53,7 +53,7 @@
#include <drivers/drv_airspeed.h>
#include <uORB/topics/differential_pressure.h>
#include <systemlib/mavlink_log.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/err.h>
#include <systemlib/airspeed.h>
+1 -1
View File
@@ -46,7 +46,7 @@
#include <uORB/topics/sensor_combined.h>
#include <drivers/drv_baro.h>
#include <systemlib/mavlink_log.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
int do_baro_calibration(orb_advert_t *mavlink_log_pub)
{
+1 -1
View File
@@ -76,7 +76,7 @@
#include <systemlib/err.h>
#include <systemlib/hysteresis/hysteresis.h>
#include <systemlib/mavlink_log.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/rc_check.h>
#include <systemlib/state_table.h>
+1 -1
View File
@@ -58,7 +58,7 @@
#include <uORB/topics/led_control.h>
#include <uORB/topics/tune_control.h>
#include <systemlib/err.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_tone_alarm.h>
+1 -1
View File
@@ -42,7 +42,7 @@
*/
#include <px4_config.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
/**
* Roll trim
@@ -39,6 +39,4 @@ px4_add_module(
../state_machine_helper.cpp
../PreflightCheck.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -1
View File
@@ -57,7 +57,7 @@
#include <uORB/topics/sensor_correction.h>
#include <drivers/drv_gyro.h>
#include <systemlib/mavlink_log.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/err.h>
static const char *sensor_name = "gyro";
+1 -1
View File
@@ -58,7 +58,7 @@
#include <drivers/drv_mag.h>
#include <drivers/drv_tone_alarm.h>
#include <systemlib/mavlink_log.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/err.h>
#include <uORB/topics/sensor_combined.h>
+1 -1
View File
@@ -48,7 +48,7 @@
#include <uORB/topics/sensor_combined.h>
#include <uORB/topics/manual_control_setpoint.h>
#include <systemlib/mavlink_log.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/err.h>
int do_trim_calibration(orb_advert_t *mavlink_log_pub)
-3
View File
@@ -38,7 +38,4 @@ px4_add_module(
-Wno-sign-compare # TODO: fix all sign-compare
SRCS
dataman.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -1
View File
@@ -60,7 +60,7 @@
#include <drivers/drv_hrt.h>
#include "dataman.h"
#include <systemlib/param/param.h>
#include <parameters/param.h>
#if defined(FLASH_BASED_DATAMAN)
#include <nuttx/clock.h>
+1 -2
View File
@@ -47,7 +47,6 @@ px4_add_module(
status_display.cpp
set_leds.cpp
DEPENDS
platforms__common
modules__uORB
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
@@ -36,7 +36,6 @@ px4_add_module(
SRCS
FixedwingAttitudeControl.cpp
DEPENDS
platforms__common
git_ecl
ecl
)
@@ -43,8 +43,8 @@
#include <px4_defines.h>
#include <px4_posix.h>
#include <px4_tasks.h>
#include <systemlib/param/param.h>
#include <systemlib/perf_counter.h>
#include <parameters/param.h>
#include <perf/perf_counter.h>
#include <uORB/Subscription.hpp>
#include <uORB/topics/actuator_controls.h>
#include <uORB/topics/airspeed.h>
@@ -65,7 +65,7 @@
#include <px4_module_params.h>
#include <px4_posix.h>
#include <px4_tasks.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <uORB/Subscription.hpp>
#include <uORB/topics/airspeed.h>
#include <uORB/topics/fw_pos_ctrl_status.h>
@@ -48,9 +48,9 @@
#include <drivers/drv_hrt.h>
#include <mathlib/mathlib.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/pid/pid.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <uORB/topics/actuator_controls.h>
#include <uORB/topics/battery_status.h>
#include <uORB/topics/manual_control_setpoint.h>
@@ -52,7 +52,7 @@
#include <ecl/l1/ecl_l1_pos_controller.h>
#include <lib/ecl/geo/geo.h>
#include <mathlib/mathlib.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <systemlib/pid/pid.h>
#include <uORB/Subscription.hpp>
#include <uORB/topics/fw_pos_ctrl_status.h>
+1 -2
View File
@@ -37,6 +37,5 @@ px4_add_module(
SRCS
gpio_led.c
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -2
View File
@@ -43,6 +43,5 @@ px4_add_module(
VtolLandDetector.cpp
RoverLandDetector.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+2 -2
View File
@@ -45,8 +45,8 @@
#include <px4_workqueue.h>
#include <px4_module.h>
#include <systemlib/hysteresis/hysteresis.h>
#include <systemlib/param/param.h>
#include <systemlib/perf_counter.h>
#include <parameters/param.h>
#include <perf/perf_counter.h>
#include <uORB/uORB.h>
#include <uORB/topics/actuator_armed.h>
#include <uORB/topics/vehicle_land_detected.h>
@@ -44,8 +44,7 @@
#include "LandDetector.h"
#include <drivers/drv_hrt.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <uORB/topics/vehicle_local_position.h>
#include <uORB/topics/vehicle_local_position_setpoint.h>
#include <uORB/topics/vehicle_attitude.h>
@@ -30,6 +30,7 @@
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
px4_add_module(
MODULE modules__landing_target_estimator
MAIN landing_target_estimator
@@ -40,6 +41,5 @@ px4_add_module(
LandingTargetEstimator.cpp
KalmanFilter.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
@@ -44,7 +44,7 @@
#include <px4_workqueue.h>
#include <drivers/drv_hrt.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <uORB/uORB.h>
#include <uORB/topics/vehicle_local_position.h>
#include <uORB/topics/vehicle_attitude.h>
+1 -2
View File
@@ -38,6 +38,5 @@ px4_add_module(
SRCS
load_mon.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -1
View File
@@ -53,7 +53,7 @@
#include <systemlib/systemlib.h>
#include <systemlib/cpuload.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <uORB/uORB.h>
#include <uORB/topics/cpuload.h>
@@ -50,6 +50,5 @@ px4_add_module(
sensors/land.cpp
sensors/landing_target.cpp
DEPENDS
platforms__common
controllib
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
@@ -1,4 +1,4 @@
#include <systemlib/param/param.h>
#include <parameters/param.h>
// 16 is max name length
+1 -3
View File
@@ -44,7 +44,5 @@ px4_add_module(
log_writer_file.cpp
log_writer_mavlink.cpp
DEPENDS
platforms__common
modules__uORB
version
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -1
View File
@@ -37,7 +37,7 @@
#include <stdint.h>
#include <pthread.h>
#include <drivers/drv_hrt.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
namespace px4
{
+1 -1
View File
@@ -39,7 +39,7 @@
#include <drivers/drv_hrt.h>
#include <uORB/Subscription.hpp>
#include <version/version.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/printload.h>
#include <px4_module.h>
+1 -1
View File
@@ -61,6 +61,6 @@ px4_add_module(
mavlink_stream.cpp
mavlink_ulog.cpp
DEPENDS
platforms__common
git_mavlink_v2
conversion
)
+1 -1
View File
@@ -44,7 +44,7 @@
#include <stdbool.h>
#include <string.h>
#include "mavlink_bridge_header.h"
#include <systemlib/param/param.h>
#include <parameters/param.h>
mavlink_system_t mavlink_system = {
1,
+2 -2
View File
@@ -64,9 +64,9 @@
#include <drivers/drv_hrt.h>
#include <arch/board/board.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/err.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <systemlib/systemlib.h>
#include <systemlib/mavlink_log.h>
#include <lib/ecl/geo/geo.h>
+2 -2
View File
@@ -53,8 +53,8 @@
#include <arpa/inet.h>
#include <drivers/device/device.h>
#endif
#include <systemlib/param/param.h>
#include <systemlib/perf_counter.h>
#include <parameters/param.h>
#include <perf/perf_counter.h>
#include <pthread.h>
#include <systemlib/mavlink_log.h>
#include <drivers/device/ringbuffer.h>
+1 -1
View File
@@ -42,7 +42,7 @@
#pragma once
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include "mavlink_bridge_header.h"
#include <uORB/uORB.h>
+1 -1
View File
@@ -75,7 +75,7 @@
#include <conversion/rotation.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/systemlib.h>
#include <systemlib/mavlink_log.h>
#include <systemlib/err.h>
+1 -1
View File
@@ -41,7 +41,7 @@
#pragma once
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <uORB/uORB.h>
#include <uORB/topics/sensor_combined.h>
#include <uORB/topics/rc_channels.h>
@@ -51,6 +51,5 @@ px4_add_module(
../mavlink_ftp.cpp
../mavlink.c
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
@@ -39,4 +39,6 @@ px4_add_module(
COMPILE_FLAGS
SRCS
mc_att_control_main.cpp
DEPENDS
mathlib
)
@@ -34,7 +34,7 @@
#include <lib/mixer/mixer.h>
#include <mathlib/math/filter/LowPassFilter2p.hpp>
#include <matrix/matrix/math.hpp>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <px4_config.h>
#include <px4_defines.h>
#include <px4_module.h>
+5 -3
View File
@@ -40,6 +40,8 @@ px4_add_module(
PositionControl.cpp
Utility/ControlMath.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
controllib
flight_tasks
git_ecl
ecl
)
@@ -43,7 +43,7 @@
#include <uORB/topics/vehicle_local_position.h>
#include <uORB/topics/vehicle_local_position_setpoint.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#pragma once
@@ -39,6 +39,4 @@ px4_add_module(
test_controlmath.cpp
../Utility/ControlMath.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+6 -2
View File
@@ -104,7 +104,7 @@ if (GENERATE_RTPS_BRIDGE)
WORKING_DIRECTORY ${PX4_SOURCE_DIR}/msg/
VERBATIM
)
add_custom_target(uorb_headers_microcdr DEPENDS ${uorb_headers_microcdr})
add_custom_target(uorb_headers_microcdr_gen DEPENDS ${uorb_headers_microcdr})
# Generate uORB serialization sources
add_custom_command(OUTPUT ${uorb_sources_microcdr}
@@ -122,7 +122,11 @@ if (GENERATE_RTPS_BRIDGE)
VERBATIM
)
px4_add_library(uorb_msgs_microcdr ${uorb_sources_microcdr})
add_dependencies(uorb_msgs_microcdr uorb_headers_microcdr uorb_headers uorb_msgs git_micro_cdr lib__micro-CDR)
add_dependencies(uorb_msgs_microcdr
uorb_headers_microcdr_gen
git_micro_cdr
lib__micro-CDR
)
target_link_libraries(uorb_msgs_microcdr PRIVATE lib__micro-CDR)
@@ -85,21 +85,19 @@ if (NOT "${config_rtps_send_topics}" STREQUAL "" OR NOT "${config_rtps_receive_t
)
add_custom_target(topic_bridge_files DEPENDS ${topic_bridge_files_out})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR}/micrortps_client)
px4_add_module(
MODULE modules__micrortps_bridge__micrortps_client
MAIN micrortps_client
STACK_MAIN 4096
INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/micrortps_client
SRCS
microRTPS_client_main.cpp
${msg_out_path}/micrortps_client/microRTPS_client.cpp
${msg_out_path}/micrortps_client/microRTPS_transport.cpp
DEPENDS
platforms__common
topic_bridge_files
uorb_headers_microcdr
)
target_link_libraries(modules__micrortps_bridge__micrortps_client PRIVATE uorb_msgs_microcdr)
endif()
+5 -11
View File
@@ -31,14 +31,8 @@
#
############################################################################
px4_add_module(
MODULE modules__muorb__adsp
INCLUDES
${PX4_SOURCE_DIR}/src/modules/uORB
SRCS
px4muorb.cpp
uORBFastRpcChannel.cpp
DEPENDS
generate_px4muorb_stubs
platforms__common
)
px4_add_library(modules__muorb__adsp
px4muorb.cpp
uORBFastRpcChannel.cpp
)
target_include_directories(modules__muorb__adsp PRIVATE ${PX4_SOURCE_DIR}/src/modules/uORB)
+1 -1
View File
@@ -42,7 +42,7 @@
#include "px4_log.h"
#include "uORB/topics/sensor_combined.h"
#include "uORB.h"
#include "systemlib/param/param.h"
#include <parameters/param.h>
#include <shmem.h>
__BEGIN_DECLS
-4
View File
@@ -30,7 +30,6 @@
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PX4_SOURCE_DIR}/cmake/cmake_hexagon")
include(hexagon_sdk)
px4_add_module(
@@ -43,7 +42,4 @@ px4_add_module(
uORBKraitFastRpcChannel.cpp
px4muorb_KraitRpcWrapper.cpp
muorb_main.cpp
DEPENDS
platforms__common
generate_px4muorb_stubs
)
@@ -36,7 +36,7 @@
#include <fcntl.h>
#include "px4muorb_KraitRpcWrapper.hpp"
#include <rpcmem.h>
#include "px4muorb.h"
#include <px4muorb.h>
#include "px4_log.h"
#include <shmem.h>
#include <drivers/drv_hrt.h>
+2 -2
View File
@@ -54,6 +54,6 @@ px4_add_module(
gpsfailure.cpp
follow_target.cpp
DEPENDS
platforms__common
git_ecl
ecl
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -1
View File
@@ -58,7 +58,7 @@
#include <navigator/navigation.h>
#include <px4_module_params.h>
#include <px4_module.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <uORB/topics/fw_pos_ctrl_status.h>
#include <uORB/topics/geofence_result.h>
#include <uORB/topics/mission.h>
@@ -41,6 +41,5 @@ px4_add_module(
position_estimator_inav_main.cpp
inertial_filter.cpp
DEPENDS
platforms__common
terrain_estimation
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
@@ -41,7 +41,7 @@
#pragma once
#include <systemlib/param/param.h>
#include <parameters/param.h>
struct position_estimator_inav_params {
float w_z_baro;
+21 -15
View File
@@ -31,19 +31,25 @@
#
############################################################################
px4_add_module(
MODULE modules__px4iofirmware
SRCS
../systemlib/hx_stream.c
../systemlib/perf_counter.c
../systemlib/pwm_limit/pwm_limit.c
adc.c
controls.c
mixer.cpp
px4io.c
registers.c
safety.c
serial.c
DEPENDS
platforms__common
add_library(px4iofirmware
hx_stream.c
../systemlib/pwm_limit/pwm_limit.c
adc.c
controls.c
mixer.cpp
px4io.c
registers.c
safety.c
serial.c
)
set_property(GLOBAL APPEND PROPERTY PX4_MODULE_LIBRARIES px4iofirmware)
target_link_libraries(px4iofirmware
PUBLIC
nuttx_apps
nuttx_arch
nuttx_c
mixer
rc
perf
)
+1 -1
View File
@@ -44,7 +44,7 @@
#include <stm32.h>
#include <drivers/drv_hrt.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#define DEBUG
#include "px4io.h"
+1 -1
View File
@@ -44,7 +44,7 @@
#include <drivers/drv_hrt.h>
#include <drivers/drv_rc_input.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <systemlib/ppm_decode.h>
#include <rc/st24.h>
#include <rc/sumd.h>
@@ -47,7 +47,7 @@
#include <string.h>
#include <stdio.h>
#include "perf_counter.h"
#include <perf/perf_counter.h>
#include "hx_stream.h"
@@ -43,7 +43,7 @@
#include <sys/types.h>
#include "perf_counter.h"
#include <perf/perf_counter.h>
struct hx_stream;
typedef struct hx_stream *hx_stream_t;
+1 -1
View File
@@ -54,7 +54,7 @@
#include <drivers/drv_pwm_output.h>
#include <drivers/drv_hrt.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
#include <systemlib/pwm_limit/pwm_limit.h>
#include <systemlib/systemlib.h>
+1 -1
View File
@@ -51,7 +51,7 @@
#include <up_internal.h>
#include <up_arch.h>
#include <stm32.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
//#define DEBUG
#include "px4io.h"
-2
View File
@@ -40,6 +40,4 @@ px4_add_module(
SRCS
replay_main.cpp
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -2
View File
@@ -42,6 +42,5 @@ px4_add_module(
sdlog2.c
logbuffer.c
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -1
View File
@@ -44,7 +44,7 @@
#define SDLOG2_RINGBUFFER_H_
#include <stdbool.h>
#include <systemlib/perf_counter.h>
#include <perf/perf_counter.h>
struct logbuffer_s {
// pointers and size are in bytes
+2 -2
View File
@@ -103,8 +103,8 @@
#include <uORB/topics/task_stack_info.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
#include <systemlib/perf_counter.h>
#include <parameters/param.h>
#include <perf/perf_counter.h>
#include <systemlib/printload.h>
#include <systemlib/mavlink_log.h>
#include <version/version.h>
+4 -2
View File
@@ -46,6 +46,8 @@ px4_add_module(
temperature_compensation.cpp
DEPENDS
platforms__common
drivers__device
battery
git_ecl
ecl
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -1
View File
@@ -43,7 +43,7 @@
#include <px4_config.h>
#include <drivers/drv_rc_input.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <mathlib/mathlib.h>
#include <uORB/topics/rc_parameter_map.h>
+3 -3
View File
@@ -70,10 +70,10 @@
#include <systemlib/airspeed.h>
#include <systemlib/systemlib.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <systemlib/err.h>
#include <systemlib/perf_counter.h>
#include <systemlib/battery.h>
#include <perf/perf_counter.h>
#include <battery/battery.h>
#include <conversion/rotation.h>
@@ -40,7 +40,7 @@
*/
#include "temperature_compensation.h"
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <px4_defines.h>
#include <px4_log.h>
@@ -42,7 +42,7 @@
#pragma once
#include <systemlib/param/param.h>
#include <parameters/param.h>
#include <mathlib/mathlib.h>
#include "common.h"
+12 -1
View File
@@ -53,6 +53,8 @@ if (NOT ${OS} STREQUAL "qurt")
simulator_mavlink.cpp)
endif()
add_subdirectory(ledsim)
px4_add_module(
MODULE modules__simulator
MAIN simulator
@@ -63,5 +65,14 @@ px4_add_module(
${SIMULATOR_SRCS}
DEPENDS
git_mavlink_v2
platforms__common
battery
conversion
drivers__ledsim
)
target_include_directories(modules__simulator INTERFACE ${PX4_SOURCE_DIR}/mavlink/include/mavlink)
add_subdirectory(accelsim)
add_subdirectory(airspeedsim)
add_subdirectory(barosim)
add_subdirectory(gpssim)
add_subdirectory(gyrosim)
@@ -0,0 +1,41 @@
############################################################################
#
# Copyright (c) 2015 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 drivers__accelsim
MAIN accelsim
SRCS
accelsim.cpp
DEPENDS
modules__simulator
)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,43 @@
############################################################################
#
# Copyright (c) 2015 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 drivers__airspeedsim
MAIN measairspeedsim
COMPILE_FLAGS
SRCS
airspeedsim.cpp
meas_airspeed_sim.cpp
DEPENDS
modules__simulator
)
@@ -0,0 +1,432 @@
/****************************************************************************
*
* Copyright (c) 2013, 2014 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.
*
****************************************************************************/
/**
* @file ets_airspeed.cpp
* @author Simon Wilks
* @author Mark Charlebois (simulator)
* @author Roman Bapst (simulator)
* Driver for the Simulated AirspeedSim Sensor based on Eagle Tree AirspeedSim V3.
*/
#include <px4_config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <semaphore.h>
#include <string.h>
#include <fcntl.h>
#include <poll.h>
#include <errno.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <systemlib/airspeed.h>
#include <systemlib/err.h>
#include <parameters/param.h>
#include <perf/perf_counter.h>
#include <drivers/drv_airspeed.h>
#include <drivers/drv_hrt.h>
#include <drivers/device/ringbuffer.h>
#include <uORB/uORB.h>
#include <uORB/topics/differential_pressure.h>
#include <uORB/topics/subsystem_info.h>
#include <simulator/simulator.h>
#include "airspeedsim.h"
AirspeedSim::AirspeedSim(int bus, int address, unsigned conversion_interval, const char *path) :
CDev("AIRSPEEDSIM", path),
_reports(nullptr),
_retries(0),
_sensor_ok(false),
_last_published_sensor_ok(true), /* initialize differently to force publication */
_measure_ticks(0),
_collect_phase(false),
_diff_pres_offset(0.0f),
_airspeed_pub(nullptr),
_subsys_pub(nullptr),
_class_instance(-1),
_conversion_interval(conversion_interval),
_sample_perf(perf_alloc(PC_ELAPSED, "airspeed_read")),
_comms_errors(perf_alloc(PC_COUNT, "airspeed_comms_errors"))
{
// enable debug() calls
_debug_enabled = false;
// work_cancel in the dtor will explode if we don't do this...
memset(&_work, 0, sizeof(_work));
}
AirspeedSim::~AirspeedSim()
{
/* make sure we are truly inactive */
stop();
if (_class_instance != -1) {
unregister_class_devname(AIRSPEED_BASE_DEVICE_PATH, _class_instance);
}
/* free any existing reports */
if (_reports != nullptr) {
delete _reports;
}
// free perf counters
perf_free(_sample_perf);
perf_free(_comms_errors);
}
int
AirspeedSim::init()
{
int ret = ERROR;
/* init base class */
if (CDev::init() != OK) {
DEVICE_DEBUG("CDev init failed");
goto out;
}
/* allocate basic report buffers */
_reports = new ringbuffer::RingBuffer(2, sizeof(differential_pressure_s));
if (_reports == nullptr) {
goto out;
}
/* register alternate interfaces if we have to */
_class_instance = register_class_devname(AIRSPEED_BASE_DEVICE_PATH);
/* publication init */
if (_class_instance == CLASS_DEVICE_PRIMARY) {
/* advertise sensor topic, measure manually to initialize valid report */
struct differential_pressure_s arp;
measure();
_reports->get(&arp);
/* measurement will have generated a report, publish */
_airspeed_pub = orb_advertise(ORB_ID(differential_pressure), &arp);
if (_airspeed_pub == nullptr) {
PX4_WARN("uORB started?");
}
}
ret = OK;
out:
return ret;
}
int
AirspeedSim::probe()
{
/* on initial power up the device may need more than one retry
for detection. Once it is running the number of retries can
be reduced
*/
_retries = 4;
int ret = measure();
// drop back to 2 retries once initialised
_retries = 2;
return ret;
}
int
AirspeedSim::ioctl(device::file_t *filp, int cmd, unsigned long arg)
{
switch (cmd) {
case SENSORIOCSPOLLRATE: {
switch (arg) {
/* switching to manual polling */
case SENSOR_POLLRATE_MANUAL:
stop();
_measure_ticks = 0;
return OK;
/* external signalling (DRDY) not supported */
case SENSOR_POLLRATE_EXTERNAL:
/* zero would be bad */
case 0:
return -EINVAL;
/* set default/max polling rate */
case SENSOR_POLLRATE_MAX:
case SENSOR_POLLRATE_DEFAULT: {
/* do we need to start internal polling? */
bool want_start = (_measure_ticks == 0);
/* set interval for next measurement to minimum legal value */
_measure_ticks = USEC2TICK(_conversion_interval);
/* if we need to start the poll state machine, do it */
if (want_start) {
start();
}
return OK;
}
/* adjust to a legal polling interval in Hz */
default: {
/* do we need to start internal polling? */
bool want_start = (_measure_ticks == 0);
/* convert hz to tick interval via microseconds */
unsigned long ticks = USEC2TICK(1000000 / arg);
/* check against maximum rate */
if (ticks < USEC2TICK(_conversion_interval)) {
return -EINVAL;
}
/* update interval for next measurement */
_measure_ticks = ticks;
/* if we need to start the poll state machine, do it */
if (want_start) {
start();
}
return OK;
}
}
}
case SENSORIOCGPOLLRATE:
if (_measure_ticks == 0) {
return SENSOR_POLLRATE_MANUAL;
}
return (1000 / _measure_ticks);
case SENSORIOCSQUEUEDEPTH: {
/* lower bound is mandatory, upper bound is a sanity check */
if ((arg < 1) || (arg > 100)) {
return -EINVAL;
}
//irqstate_t flags = px4_enter_critical_section();
if (!_reports->resize(arg)) {
//px4_leave_critical_section(flags);
return -ENOMEM;
}
//px4_leave_critical_section(flags);
return OK;
}
case SENSORIOCRESET:
/* XXX implement this */
return -EINVAL;
case AIRSPEEDIOCSSCALE: {
struct airspeed_scale *s = (struct airspeed_scale *)arg;
_diff_pres_offset = s->offset_pa;
return OK;
}
case AIRSPEEDIOCGSCALE: {
struct airspeed_scale *s = (struct airspeed_scale *)arg;
s->offset_pa = _diff_pres_offset;
s->scale = 1.0f;
return OK;
}
default:
/* give it to the superclass */
//return I2C::ioctl(filp, cmd, arg); XXX SIM should be super class
return 0;
}
}
ssize_t
AirspeedSim::read(device::file_t *filp, char *buffer, size_t buflen)
{
unsigned count = buflen / sizeof(differential_pressure_s);
differential_pressure_s *abuf = reinterpret_cast<differential_pressure_s *>(buffer);
int ret = 0;
/* buffer must be large enough */
if (count < 1) {
return -ENOSPC;
}
/* if automatic measurement is enabled */
if (_measure_ticks > 0) {
/*
* While there is space in the caller's buffer, and reports, copy them.
* Note that we may be pre-empted by the workq thread while we are doing this;
* we are careful to avoid racing with them.
*/
while (count--) {
if (_reports->get(abuf)) {
ret += sizeof(*abuf);
abuf++;
}
}
/* if there was no data, warn the caller */
return ret ? ret : -EAGAIN;
}
/* manual measurement - run one conversion */
do {
_reports->flush();
/* trigger a measurement */
if (OK != measure()) {
ret = -EIO;
break;
}
/* wait for it to complete */
usleep(_conversion_interval);
/* run the collection phase */
if (OK != collect()) {
ret = -EIO;
break;
}
/* state machine will have generated a report, copy it out */
if (_reports->get(abuf)) {
ret = sizeof(*abuf);
}
} while (0);
return ret;
}
void
AirspeedSim::start()
{
/* reset the report ring and state machine */
_collect_phase = false;
_reports->flush();
/* schedule a cycle to start things */
work_queue(HPWORK, &_work, (worker_t)&AirspeedSim::cycle_trampoline, this, 1);
}
void
AirspeedSim::stop()
{
work_cancel(HPWORK, &_work);
}
void
AirspeedSim::update_status()
{
if (_sensor_ok != _last_published_sensor_ok) {
/* notify about state change */
struct subsystem_info_s info = {};
info.present = true;
info.enabled = true;
info.ok = _sensor_ok;
info.subsystem_type = subsystem_info_s::SUBSYSTEM_TYPE_DIFFPRESSURE;
if (_subsys_pub != nullptr) {
orb_publish(ORB_ID(subsystem_info), _subsys_pub, &info);
} else {
_subsys_pub = orb_advertise(ORB_ID(subsystem_info), &info);
}
_last_published_sensor_ok = _sensor_ok;
}
}
void
AirspeedSim::cycle_trampoline(void *arg)
{
AirspeedSim *dev = (AirspeedSim *)arg;
dev->cycle();
// XXX we do not know if this is
// really helping - do not update the
// subsys state right now
//dev->update_status();
}
void
AirspeedSim::print_info()
{
perf_print_counter(_sample_perf);
perf_print_counter(_comms_errors);
PX4_INFO("poll interval: %u ticks", _measure_ticks);
_reports->print_info("report queue");
}
void
AirspeedSim::new_report(const differential_pressure_s &report)
{
_reports->force(&report);
}
int
AirspeedSim::transfer(const uint8_t *send, unsigned send_len, uint8_t *recv, unsigned recv_len)
{
if (recv_len > 0) {
// this is equivalent to the collect phase
Simulator *sim = Simulator::getInstance();
if (sim == nullptr) {
PX4_ERR("Error BARO_SIM::transfer no simulator");
return -ENODEV;
}
PX4_DEBUG("BARO_SIM::transfer getting sample");
sim->getAirspeedSample(recv, recv_len);
} else {
// we don't need measure phase
}
return 0;
}
@@ -0,0 +1,181 @@
/****************************************************************************
*
* Copyright (c) 2013, 2014 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.
*
****************************************************************************/
/**
* @file airspeed.h
* @author Simon Wilks
*
* Generic driver for airspeed sensors connected via I2C.
*/
#include <px4_config.h>
#include <px4_defines.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <semaphore.h>
#include <string.h>
#include <fcntl.h>
#include <poll.h>
#include <errno.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <px4_workqueue.h>
#include <arch/board/board.h>
#include <systemlib/airspeed.h>
#include <systemlib/err.h>
#include <parameters/param.h>
#include <perf/perf_counter.h>
#include <drivers/drv_airspeed.h>
#include <drivers/drv_hrt.h>
#include <drivers/device/ringbuffer.h>
#include <drivers/device/device.h>
#include <uORB/uORB.h>
#include <uORB/topics/differential_pressure.h>
#include <uORB/topics/subsystem_info.h>
/* Default I2C bus */
#define PX4_I2C_BUS_DEFAULT PX4_I2C_BUS_EXPANSION
#ifndef CONFIG_SCHED_WORKQUEUE
# error This requires CONFIG_SCHED_WORKQUEUE.
#endif
class __EXPORT AirspeedSim : public device::CDev
{
public:
AirspeedSim(int bus, int address, unsigned conversion_interval, const char *path);
virtual ~AirspeedSim();
virtual int init();
virtual ssize_t read(device::file_t *filp, char *buffer, size_t buflen);
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg);
/**
* Diagnostics - print some basic information about the driver.
*/
virtual void print_info();
private:
ringbuffer::RingBuffer *_reports;
unsigned _retries; // XXX this should come from the SIM class
/* this class has pointer data members and should not be copied */
AirspeedSim(const AirspeedSim &);
AirspeedSim &operator=(const AirspeedSim &);
protected:
virtual int probe();
/**
* Perform a poll cycle; collect from the previous measurement
* and start a new one.
*/
virtual void cycle() = 0;
virtual int measure() = 0;
virtual int collect() = 0;
virtual int transfer(const uint8_t *send, unsigned send_len,
uint8_t *recv, unsigned recv_len);
/**
* Update the subsystem status
*/
void update_status();
struct work_s _work;
bool _sensor_ok;
bool _last_published_sensor_ok;
unsigned _measure_ticks;
bool _collect_phase;
float _diff_pres_offset;
orb_advert_t _airspeed_pub;
orb_advert_t _subsys_pub;
int _class_instance;
unsigned _conversion_interval;
perf_counter_t _sample_perf;
perf_counter_t _comms_errors;
/**
* Test whether the device supported by the driver is present at a
* specific address.
*
* @param address The I2C bus address to probe.
* @return True if the device is present.
*/
int probe_address(uint8_t address);
/**
* Initialise the automatic measurement state machine and start it.
*
* @note This function is called at open and error time. It might make sense
* to make it more aggressive about resetting the bus in case of errors.
*/
void start();
/**
* Stop the automatic measurement state machine.
*/
void stop();
/**
* Static trampoline from the workq context; because we don't have a
* generic workq wrapper yet.
*
* @param arg Instance pointer for the driver that is polling.
*/
static void cycle_trampoline(void *arg);
/**
* add a new report to the reports queue
*
* @param report differential_pressure_s report
*/
void new_report(const differential_pressure_s &report);
};
@@ -0,0 +1,553 @@
/****************************************************************************
*
* Copyright (c) 2013, 2014, 2017 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.
*
****************************************************************************/
/**
* @file meas_airspeed_sim.cpp
* @author Lorenz Meier <lorenz@px4.io>
* @author Sarthak Kaingade
* @author Simon Wilks
* @author Thomas Gubler
* @author Roman Bapst
*
* Driver for a simulated airspeed sensor.
*
*/
#include <px4_config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <semaphore.h>
#include <string.h>
#include <fcntl.h>
#include <poll.h>
#include <errno.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <systemlib/airspeed.h>
#include <systemlib/err.h>
#include <parameters/param.h>
#include <perf/perf_counter.h>
#include <mathlib/math/filter/LowPassFilter2p.hpp>
#include <drivers/drv_airspeed.h>
#include <drivers/drv_hrt.h>
#include <uORB/uORB.h>
#include <uORB/topics/differential_pressure.h>
#include <uORB/topics/subsystem_info.h>
#include <uORB/topics/system_power.h>
#include "airspeedsim.h"
/* I2C bus address is 1010001x */
#define I2C_ADDRESS_MS4525DO 0x28 /**< 7-bit address. Depends on the order code (this is for code "I") */
#define PATH_MS4525 "/dev/ms4525"
/* The MS5525DSO address is 111011Cx, where C is the complementary value of the pin CSB */
#define I2C_ADDRESS_MS5525DSO 0x77 //0x77/* 7-bit address, addr. pin pulled low */
#define PATH_MS5525 "/dev/ms5525"
/* Register address */
#define ADDR_READ_MR 0x00 /* write to this address to start conversion */
/* Measurement rate is 100Hz */
#define MEAS_RATE 100
#define MEAS_DRIVER_FILTER_FREQ 1.2f
#define CONVERSION_INTERVAL (1000000 / MEAS_RATE) /* microseconds */
class MEASAirspeedSim : public AirspeedSim
{
public:
MEASAirspeedSim(int bus, int address = I2C_ADDRESS_MS4525DO, const char *path = PATH_MS4525);
protected:
/**
* Perform a poll cycle; collect from the previous measurement
* and start a new one.
*/
virtual void cycle();
virtual int measure();
virtual int collect();
math::LowPassFilter2p _filter;
/**
* Correct for 5V rail voltage variations
*/
void voltage_correction(float &diff_pres_pa, float &temperature);
int _t_system_power;
struct system_power_s system_power;
};
/*
* Driver 'main' command.
*/
extern "C" __EXPORT int measairspeedsim_main(int argc, char *argv[]);
MEASAirspeedSim::MEASAirspeedSim(int bus, int address, const char *path) : AirspeedSim(bus, address,
CONVERSION_INTERVAL, path),
_filter(MEAS_RATE, MEAS_DRIVER_FILTER_FREQ),
_t_system_power(-1),
system_power{}
{}
int
MEASAirspeedSim::measure()
{
int ret;
/*
* Send the command to begin a measurement.
*/
uint8_t cmd = 0;
ret = transfer(&cmd, 1, nullptr, 0);
if (OK != ret) {
perf_count(_comms_errors);
}
return ret;
}
int
MEASAirspeedSim::collect()
{
int ret = -EIO;
/* read from the sensor */
#pragma pack(push, 1)
struct {
float temperature;
float diff_pressure;
} airspeed_report;
#pragma pack(pop)
perf_begin(_sample_perf);
ret = transfer(nullptr, 0, (uint8_t *)&airspeed_report, sizeof(airspeed_report));
if (ret < 0) {
perf_count(_comms_errors);
perf_end(_sample_perf);
return ret;
}
uint8_t status = 0;
switch (status) {
case 0:
break;
case 1:
/* fallthrough */
case 2:
/* fallthrough */
case 3:
perf_count(_comms_errors);
perf_end(_sample_perf);
return -EAGAIN;
}
float temperature = airspeed_report.temperature;
float diff_press_pa_raw = airspeed_report.diff_pressure * 100.0f; // convert from millibar to bar
struct differential_pressure_s report;
report.timestamp = hrt_absolute_time();
report.error_count = perf_event_count(_comms_errors);
report.temperature = temperature;
report.differential_pressure_filtered_pa = _filter.apply(diff_press_pa_raw);
report.differential_pressure_raw_pa = diff_press_pa_raw;
if (_airspeed_pub != nullptr && !(_pub_blocked)) {
/* publish it */
orb_publish(ORB_ID(differential_pressure), _airspeed_pub, &report);
}
new_report(report);
/* notify anyone waiting for data */
poll_notify(POLLIN);
ret = OK;
perf_end(_sample_perf);
return ret;
}
void
MEASAirspeedSim::cycle()
{
int ret;
/* collection phase? */
if (_collect_phase) {
/* perform collection */
ret = collect();
if (OK != ret) {
/* restart the measurement state machine */
start();
_sensor_ok = false;
return;
}
/* next phase is measurement */
_collect_phase = false;
/*
* Is there a collect->measure gap?
*/
if (_measure_ticks > USEC2TICK(CONVERSION_INTERVAL)) {
/* schedule a fresh cycle call when we are ready to measure again */
work_queue(HPWORK,
&_work,
(worker_t)&AirspeedSim::cycle_trampoline,
this,
_measure_ticks - USEC2TICK(CONVERSION_INTERVAL));
return;
}
}
/* measurement phase */
ret = measure();
if (OK != ret) {
DEVICE_DEBUG("measure error");
}
_sensor_ok = (ret == OK);
/* next phase is collection */
_collect_phase = true;
/* schedule a fresh cycle call when the measurement is done */
work_queue(HPWORK,
&_work,
(worker_t)&AirspeedSim::cycle_trampoline,
this,
USEC2TICK(CONVERSION_INTERVAL));
}
/**
* Local functions in support of the shell command.
*/
namespace meas_airspeed_sim
{
MEASAirspeedSim *g_dev = nullptr;
int start(int i2c_bus);
int stop();
int test();
int reset();
int info();
/**
* Start the driver.
*
* This function call only returns once the driver is up and running
* or failed to detect the sensor.
*/
int
start(int i2c_bus)
{
int fd;
if (g_dev != nullptr) {
PX4_WARN("already started");
}
/* create the driver, try the MS4525DO first */
g_dev = new MEASAirspeedSim(i2c_bus, I2C_ADDRESS_MS4525DO, PATH_MS4525);
/* check if the MS4525DO was instantiated */
if (g_dev == nullptr) {
goto fail;
}
/* try the MS5525DSO next if init fails */
if (OK != g_dev->AirspeedSim::init()) {
delete g_dev;
g_dev = new MEASAirspeedSim(i2c_bus, I2C_ADDRESS_MS5525DSO, PATH_MS5525);
/* check if the MS5525DSO was instantiated */
if (g_dev == nullptr) {
goto fail;
}
/* both versions failed if the init for the MS5525DSO fails, give up */
if (OK != g_dev->AirspeedSim::init()) {
goto fail;
}
}
/* set the poll rate to default, starts automatic data collection */
fd = px4_open(PATH_MS4525, O_RDONLY);
if (fd < 0) {
goto fail;
}
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
goto fail;
}
return 0;
fail:
if (g_dev != nullptr) {
delete g_dev;
g_dev = nullptr;
}
PX4_ERR("no MS4525 airspeedSim sensor connected");
return 1;
}
/**
* Stop the driver
*/
int
stop()
{
if (g_dev != nullptr) {
delete g_dev;
g_dev = nullptr;
} else {
PX4_ERR("driver not running");
}
return 0;
}
/**
* Perform some basic functional tests on the driver;
* make sure we can collect data from the sensor in polled
* and automatic modes.
*/
int
test()
{
struct differential_pressure_s report;
ssize_t sz;
int ret;
int fd = px4_open(PATH_MS4525, O_RDONLY);
if (fd < 0) {
PX4_ERR("%s open failed (try 'meas_airspeed_sim start' if the driver is not running", PATH_MS4525);
return 1;
}
/* do a simple demand read */
sz = px4_read(fd, &report, sizeof(report));
if (sz != sizeof(report)) {
PX4_ERR("immediate read failed");
return 1;
}
print_message(report);
/* start the sensor polling at 2Hz */
if (OK != px4_ioctl(fd, SENSORIOCSPOLLRATE, 2)) {
PX4_WARN("failed to set 2Hz poll rate");
}
/* read the sensor 5x and report each value */
for (unsigned i = 0; i < 5; i++) {
struct pollfd fds;
/* wait for data to be ready */
fds.fd = fd;
fds.events = POLLIN;
ret = poll(&fds, 1, 2000);
if (ret != 1) {
warnx("timed out");
}
/* now go get it */
sz = read(fd, &report, sizeof(report));
if (sz != sizeof(report)) {
PX4_WARN("periodic read failed");
}
print_message(report);
}
/* reset the sensor polling to its default rate */
if (OK != ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT)) {
PX4_ERR("failed to set default rate");
return 1;
}
PX4_WARN("PASS");
return 0;
}
/**
* Reset the driver.
*/
int
reset()
{
int fd = open(PATH_MS4525, O_RDONLY);
if (fd < 0) {
PX4_ERR("failed ");
return 1;
}
if (ioctl(fd, SENSORIOCRESET, 0) < 0) {
PX4_ERR("driver reset failed");
close(fd);
return 1;
}
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
PX4_ERR("driver poll restart failed");
close(fd);
return 1;
}
close(fd);
return 0;
}
/**
* Print a little info about the driver.
*/
int
info()
{
if (g_dev == nullptr) {
PX4_WARN("driver not running");
return -1;
}
printf("state @ %p\n", g_dev);
g_dev->print_info();
return 0;
}
} // namespace
static void
meas_airspeed_usage()
{
PX4_WARN("usage: measairspeedsim command [options]");
PX4_WARN("options:");
PX4_WARN("\t-b --bus i2cbus (%d)", 1);
PX4_WARN("command:");
PX4_WARN("\tstart|stop|reset|test|info");
}
int
measairspeedsim_main(int argc, char *argv[])
{
int i2c_bus = 1;//PX4_I2C_BUS_DEFAULT;
int i;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) {
if (argc > i + 1) {
i2c_bus = atoi(argv[i + 1]);
}
}
}
int ret = 1;
/*
* Start/load the driver.
*/
if (!strcmp(argv[1], "start")) {
return meas_airspeed_sim::start(i2c_bus);
}
/*
* Stop the driver
*/
if (!strcmp(argv[1], "stop")) {
return meas_airspeed_sim::stop();
}
/*
* Test the driver/device.
*/
if (!strcmp(argv[1], "test")) {
return meas_airspeed_sim::test();
}
/*
* Reset the driver.
*/
if (!strcmp(argv[1], "reset")) {
return meas_airspeed_sim::reset();
}
/*
* Print driver information.
*/
if (!strcmp(argv[1], "info") || !strcmp(argv[1], "status")) {
return meas_airspeed_sim::info();
}
meas_airspeed_usage();
return ret;
}
@@ -0,0 +1,42 @@
############################################################################
#
# Copyright (c) 2015 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 drivers__barosim
MAIN barosim
COMPILE_FLAGS
SRCS
baro.cpp
DEPENDS
modules__simulator
)
+355
View File
@@ -0,0 +1,355 @@
/****************************************************************************
*
* Copyright (c) 2012-2015 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.
*
****************************************************************************/
/**
* @file baro.cpp
* Driver for the simulated barometric pressure sensor
*/
#include <inttypes.h>
#include <px4_config.h>
#include <px4_defines.h>
#include <px4_time.h>
#include <px4_getopt.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <semaphore.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <arch/board/board.h>
#include <board_config.h>
#include <drivers/device/device.h>
#include <drivers/drv_baro.h>
#include <drivers/drv_hrt.h>
#include <drivers/device/ringbuffer.h>
#include <simulator/simulator.h>
#include <perf/perf_counter.h>
#include <systemlib/err.h>
#include "barosim.h"
#include "VirtDevObj.hpp"
/* helper macro for arithmetic - returns the square of the argument */
#define POW2(_x) ((_x) * (_x))
#define BAROSIM_DEV_PATH "/dev/barosim"
#define BAROSIM_MEASURE_INTERVAL_US (10000)
using namespace DriverFramework;
class BAROSIM : public VirtDevObj
{
public:
BAROSIM(const char *path);
virtual ~BAROSIM();
virtual int init() override;
virtual int devIOCTL(unsigned long cmd, unsigned long arg) override;
/**
* Diagnostics - print some basic information about the driver.
*/
void print_info();
protected:
ringbuffer::RingBuffer *_reports;
/* last report */
struct baro_report report;
orb_advert_t _baro_topic;
int _orb_class_instance;
perf_counter_t _sample_perf;
perf_counter_t _measure_perf;
perf_counter_t _comms_errors;
/**
* Get the internal / external state
*
* @return true if the sensor is not on the main MCU board
*/
bool is_external() { return (_orb_class_instance == 0); /* XXX put this into the interface class */ }
virtual void _measure() override;
/**
* Collect the result of the most recent measurement.
*/
virtual int collect();
};
static BAROSIM *g_barosim = nullptr;
/*
* Driver 'main' command.
*/
extern "C" __EXPORT int barosim_main(int argc, char *argv[]);
BAROSIM::BAROSIM(const char *path) :
VirtDevObj("BAROSIM", path, BARO_BASE_DEVICE_PATH, BAROSIM_MEASURE_INTERVAL_US),
_reports(nullptr),
report{},
_baro_topic(nullptr),
_orb_class_instance(-1),
_sample_perf(perf_alloc(PC_ELAPSED, "barosim_read")),
_measure_perf(perf_alloc(PC_ELAPSED, "barosim_measure")),
_comms_errors(perf_alloc(PC_COUNT, "barosim_comms_errors"))
{
}
BAROSIM::~BAROSIM()
{
/* make sure we are truly inactive */
stop();
setSampleInterval(0);
/* free any existing reports */
if (_reports != nullptr) {
delete _reports;
}
// free perf counters
perf_free(_sample_perf);
perf_free(_measure_perf);
perf_free(_comms_errors);
}
int
BAROSIM::init()
{
int ret;
struct baro_report brp = {};
ret = VirtDevObj::init();
if (ret != OK) {
PX4_ERR("VirtDevObj init failed");
goto out;
}
/* allocate basic report buffers */
_reports = new ringbuffer::RingBuffer(2, sizeof(baro_report));
if (_reports == nullptr) {
PX4_ERR("can't get memory for reports");
ret = -ENOMEM;
goto out;
}
_reports->flush();
_baro_topic = orb_advertise_multi(ORB_ID(sensor_baro), &brp,
&_orb_class_instance, (is_external()) ? ORB_PRIO_HIGH : ORB_PRIO_DEFAULT);
if (_baro_topic == nullptr) {
PX4_ERR("failed to create sensor_baro publication");
return -ENODEV;
}
/* fill report structures */
start();
out:
return ret;
}
int
BAROSIM::devIOCTL(unsigned long cmd, unsigned long arg)
{
/* give it to the bus-specific superclass */
// return bus_ioctl(filp, cmd, arg);
return VirtDevObj::devIOCTL(cmd, arg);
}
void
BAROSIM::_measure()
{
collect();
}
int
BAROSIM::collect()
{
bool status;
simulator::RawBaroData raw_baro;
perf_begin(_sample_perf);
report.timestamp = hrt_absolute_time();
report.error_count = perf_event_count(_comms_errors);
/* read requested */
Simulator *sim = Simulator::getInstance();
if (sim == nullptr) {
PX4_ERR("Error BAROSIM_DEV::transfer no simulator");
return -ENODEV;
}
PX4_DEBUG("BAROSIM_DEV::transfer getting sample");
status = sim->getBaroSample((uint8_t *)(&raw_baro), sizeof(raw_baro));
if (!status) {
perf_count(_comms_errors);
perf_end(_sample_perf);
return -1;
}
report.pressure = raw_baro.pressure;
report.temperature = raw_baro.temperature;
/* fake device ID */
report.device_id = 478459;
/* publish it */
if (!(m_pub_blocked)) {
if (_baro_topic != nullptr) {
/* publish it */
orb_publish(ORB_ID(sensor_baro), _baro_topic, &report);
} else {
PX4_WARN("BAROSIM::collect _baro_topic not initialized");
}
}
_reports->force(&report);
perf_end(_sample_perf);
return OK;
}
void
BAROSIM::print_info()
{
perf_print_counter(_sample_perf);
perf_print_counter(_comms_errors);
PX4_INFO("poll interval: %u usec", m_sample_interval_usecs);
_reports->print_info("report queue");
PX4_INFO("TEMP: %f", (double)report.temperature);
PX4_INFO("P: %.3f", (double)report.pressure);
}
namespace barosim
{
/**
* Start the driver.
*
* This function call only returns once the driver
* is either successfully up and running or failed to start.
*/
static int
start()
{
g_barosim = new BAROSIM(BAROSIM_DEV_PATH);
if (g_barosim != nullptr && OK != g_barosim->init()) {
delete g_barosim;
g_barosim = nullptr;
PX4_ERR("bus init failed");
return false;
}
return 0;
}
/**
* Print a little info about the driver.
*/
static int
info()
{
if (g_barosim != nullptr) {
PX4_INFO("%s", BAROSIM_DEV_PATH);
g_barosim->print_info();
}
return 0;
}
static void
usage()
{
PX4_WARN("missing command: try 'start', 'info'");
}
}; // namespace barosim
int
barosim_main(int argc, char *argv[])
{
int ret;
if (argc < 2) {
barosim::usage();
return 1;
}
const char *verb = argv[1];
/*
* Start/load the driver.
*/
if (!strcmp(verb, "start")) {
ret = barosim::start();
}
/*
* Print driver information.
*/
else if (!strcmp(verb, "info")) {
ret = barosim::info();
} else {
barosim::usage();
return 1;
}
return ret;
}
+42
View File
@@ -0,0 +1,42 @@
/****************************************************************************
*
* Copyright (C) 2012-2013 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.
*
****************************************************************************/
/**
* @file barosim.h
*
* A simulated Barometer.
*/
#pragma once
#include "VirtDevObj.hpp"
@@ -0,0 +1,42 @@
############################################################################
#
# Copyright (c) 2015 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 drivers__gpssim
MAIN gpssim
COMPILE_FLAGS
SRCS
gpssim.cpp
DEPENDS
modules__simulator
)
+633
View File
@@ -0,0 +1,633 @@
/****************************************************************************
*
* Copyright (c) 2015 Roman Bapst. 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 gpssim.cpp
* Simulated GPS driver
*/
#include <sys/types.h>
#include <px4_defines.h>
#include <px4_getopt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <semaphore.h>
#include <string.h>
#include <fcntl.h>
#include <poll.h>
#include <errno.h>
#include <stdio.h>
#include <random>
#include <math.h>
#include <unistd.h>
#include <fcntl.h>
#include <px4_config.h>
#include <px4_tasks.h>
#include <drivers/drv_hrt.h>
#include <drivers/device/device.h>
#include <drivers/drv_gps.h>
#include <uORB/uORB.h>
#include <uORB/topics/vehicle_gps_position.h>
#include <uORB/topics/satellite_info.h>
#include <simulator/simulator.h>
#include "DevMgr.hpp"
#include "VirtDevObj.hpp"
using namespace DriverFramework;
#define GPS_DRIVER_MODE_UBX_SIM
#define GPSSIM_DEVICE_PATH "/dev/gpssim"
#define TIMEOUT_100MS 100000
#define RATE_MEASUREMENT_PERIOD 5000000
/* class for dynamic allocation of satellite info data */
class GPS_Sat_Info
{
public:
struct satellite_info_s _data;
};
class GPSSIM : public VirtDevObj
{
public:
GPSSIM(const char *uart_path, bool fake_gps, bool enable_sat_info,
int fix_type, int num_sat, int noise_multiplier);
virtual ~GPSSIM();
virtual int init();
virtual int devIOCTL(unsigned long cmd, unsigned long arg);
void set(int fix_type, int num_sat, int noise_multiplier);
/**
* Diagnostics - print some basic information about the driver.
*/
void print_info();
protected:
virtual void _measure() {}
private:
bool _task_should_exit; ///< flag to make the main worker task exit
int _serial_fd; ///< serial interface to GPS
unsigned _baudrate; ///< current baudrate
char _port[20]; ///< device / serial port path
volatile int _task; ///< worker task
bool _healthy; ///< flag to signal if the GPS is ok
bool _baudrate_changed; ///< flag to signal that the baudrate with the GPS has changed
bool _mode_changed; ///< flag that the GPS mode has changed
//gps_driver_mode_t _mode; ///< current mode
GPS_Sat_Info *_Sat_Info; ///< instance of GPS sat info data object
struct vehicle_gps_position_s _report_gps_pos; ///< uORB topic for gps position
orb_advert_t _report_gps_pos_pub; ///< uORB pub for gps position
struct satellite_info_s *_p_report_sat_info; ///< pointer to uORB topic for satellite info
orb_advert_t _report_sat_info_pub; ///< uORB pub for satellite info
float _rate; ///< position update rate
SyncObj _sync;
int _fix_type;
int _num_sat;
int _noise_multiplier;
std::default_random_engine _gen;
/**
* Try to configure the GPS, handle outgoing communication to the GPS
*/
void config();
/**
* Trampoline to the worker task
*/
static void task_main_trampoline(void *arg);
/**
* Worker task: main GPS thread that configures the GPS and parses incoming data, always running
*/
void task_main();
/**
* Set the baudrate of the UART to the GPS
*/
int set_baudrate(unsigned baud);
/**
* Send a reset command to the GPS
*/
void cmd_reset();
int receive(int timeout);
};
/*
* Driver 'main' command.
*/
extern "C" __EXPORT int gpssim_main(int argc, char *argv[]);
namespace
{
GPSSIM *g_dev = nullptr;
}
GPSSIM::GPSSIM(const char *uart_path, bool fake_gps, bool enable_sat_info,
int fix_type, int num_sat, int noise_multiplier) :
VirtDevObj("gps", GPSSIM_DEVICE_PATH, nullptr, 1e6 / 10),
_task_should_exit(false),
//_healthy(false),
//_mode_changed(false),
//_mode(GPS_DRIVER_MODE_UBX),
//_Helper(nullptr),
_Sat_Info(nullptr),
_report_gps_pos_pub(nullptr),
_p_report_sat_info(nullptr),
_report_sat_info_pub(nullptr),
_rate(0.0f),
_fix_type(fix_type),
_num_sat(num_sat),
_noise_multiplier(noise_multiplier)
{
// /* store port name */
// strncpy(_port, uart_path, sizeof(_port));
// /* enforce null termination */
// _port[sizeof(_port) - 1] = '\0';
/* we need this potentially before it could be set in task_main */
g_dev = this;
memset(&_report_gps_pos, 0, sizeof(_report_gps_pos));
/* create satellite info data object if requested */
if (enable_sat_info) {
_Sat_Info = new (GPS_Sat_Info);
_p_report_sat_info = &_Sat_Info->_data;
memset(_p_report_sat_info, 0, sizeof(*_p_report_sat_info));
}
}
GPSSIM::~GPSSIM()
{
delete _Sat_Info;
/* tell the task we want it to go away */
_task_should_exit = true;
/* spin waiting for the task to stop */
for (unsigned i = 0; (i < 10) && (_task != -1); i++) {
/* give it another 100ms */
usleep(100000);
}
/* well, kill it anyway, though this will probably crash */
if (_task != -1) {
px4_task_delete(_task);
}
g_dev = nullptr;
}
int
GPSSIM::init()
{
int ret = PX4_ERROR;
/* do regular cdev init */
if (VirtDevObj::init() != OK) {
goto out;
}
/* start the GPS driver worker task */
_task = px4_task_spawn_cmd("gps", SCHED_DEFAULT,
SCHED_PRIORITY_DEFAULT, 1500, (px4_main_t)&GPSSIM::task_main_trampoline, nullptr);
if (_task < 0) {
PX4_ERR("task start failed: %d", errno);
return -errno;
}
ret = OK;
out:
return ret;
}
int
GPSSIM::devIOCTL(unsigned long cmd, unsigned long arg)
{
_sync.lock();
int ret = OK;
switch (cmd) {
case SENSORIOCRESET:
cmd_reset();
break;
default:
/* give it to parent if no one wants it */
ret = VirtDevObj::devIOCTL(cmd, arg);
break;
}
_sync.unlock();
return ret;
}
void
GPSSIM::task_main_trampoline(void *arg)
{
g_dev->task_main();
}
int
GPSSIM::receive(int timeout)
{
Simulator *sim = Simulator::getInstance();
simulator::RawGPSData gps;
sim->getGPSSample((uint8_t *)&gps, sizeof(gps));
static int64_t timestamp_last = 0;
if (gps.timestamp != timestamp_last) {
_report_gps_pos.timestamp = hrt_absolute_time();
_report_gps_pos.lat = gps.lat;
_report_gps_pos.lon = gps.lon;
_report_gps_pos.alt = gps.alt;
_report_gps_pos.eph = (float)gps.eph * 1e-2f;
_report_gps_pos.epv = (float)gps.epv * 1e-2f;
_report_gps_pos.vel_m_s = (float)(gps.vel) / 100.0f;
_report_gps_pos.vel_n_m_s = (float)(gps.vn) / 100.0f;
_report_gps_pos.vel_e_m_s = (float)(gps.ve) / 100.0f;
_report_gps_pos.vel_d_m_s = (float)(gps.vd) / 100.0f;
_report_gps_pos.cog_rad = (float)(gps.cog) * 3.1415f / (100.0f * 180.0f);
_report_gps_pos.fix_type = gps.fix_type;
_report_gps_pos.satellites_used = gps.satellites_visible;
timestamp_last = gps.timestamp;
// check for data set by the user
_report_gps_pos.fix_type = (_fix_type < 0) ? _report_gps_pos.fix_type : _fix_type;
_report_gps_pos.satellites_used = (_num_sat < 0) ? _report_gps_pos.satellites_used : _num_sat;
// use normal distribution for noise
std::normal_distribution<float> normal_distribution(0.0f, 1.0f);
_report_gps_pos.lat += (int32_t)(_noise_multiplier * normal_distribution(_gen));
_report_gps_pos.lon += (int32_t)(_noise_multiplier * normal_distribution(_gen));
return 1;
} else {
usleep(timeout);
return 0;
}
}
void
GPSSIM::task_main()
{
/* loop handling received serial bytes and also configuring in between */
while (!_task_should_exit) {
// GPS is obviously detected successfully, reset statistics
//_Helper->reset_update_rates();
int recv_ret = receive(TIMEOUT_100MS);
if (recv_ret > 0) {
/* opportunistic publishing - else invalid data would end up on the bus */
if (_report_gps_pos_pub != nullptr) {
orb_publish(ORB_ID(vehicle_gps_position), _report_gps_pos_pub, &_report_gps_pos);
} else {
_report_gps_pos_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report_gps_pos);
}
if (_p_report_sat_info) {
if (_report_sat_info_pub != nullptr) {
orb_publish(ORB_ID(satellite_info), _report_sat_info_pub, _p_report_sat_info);
} else {
_report_sat_info_pub = orb_advertise(ORB_ID(satellite_info), _p_report_sat_info);
}
}
}
}
PX4_INFO("exiting");
/* tell the dtor that we are exiting */
_task = -1;
}
void
GPSSIM::cmd_reset()
{
}
void
GPSSIM::print_info()
{
//GPS Mode
PX4_INFO("protocol: SIM");
PX4_INFO("port: %s, baudrate: %d, status: %s", _port, _baudrate, (_healthy) ? "OK" : "NOT OK");
PX4_INFO("sat info: %s, noise: %d, jamming detected: %s",
(_p_report_sat_info != nullptr) ? "enabled" : "disabled",
_report_gps_pos.noise_per_ms,
_report_gps_pos.jamming_indicator == 255 ? "YES" : "NO");
if (_report_gps_pos.timestamp != 0) {
print_message(_report_gps_pos);
}
usleep(100000);
}
void
GPSSIM::set(int fix_type, int num_sat, int noise_multiplier)
{
_fix_type = fix_type;
_num_sat = num_sat;
_noise_multiplier = noise_multiplier;
PX4_INFO("Parameters set");
}
/**
* Local functions in support of the shell command.
*/
namespace gpssim
{
GPSSIM *g_dev = nullptr;
void start(const char *uart_path, bool fake_gps, bool enable_sat_info,
int fix_type, int num_sat, int noise_multiplier);
void stop();
void test();
void reset();
void info();
void usage(const char *reason);
/**
* Start the driver.
*/
void
start(const char *uart_path, bool fake_gps, bool enable_sat_info, int fix_type, int num_sat, int noise_multiplier)
{
DevHandle h;
/* create the driver */
g_dev = new GPSSIM(uart_path, fake_gps, enable_sat_info, fix_type, num_sat, noise_multiplier);
if (g_dev == nullptr) {
goto fail;
}
if (OK != g_dev->init()) {
goto fail;
}
/* set the poll rate to default, starts automatic data collection */
DevMgr::getHandle(GPSSIM_DEVICE_PATH, h);
if (!h.isValid()) {
PX4_ERR("getHandle failed: %s", GPSSIM_DEVICE_PATH);
goto fail;
}
return;
fail:
if (g_dev != nullptr) {
delete g_dev;
g_dev = nullptr;
}
PX4_ERR("start failed");
}
/**
* Stop the driver.
*/
void
stop()
{
delete g_dev;
g_dev = nullptr;
}
/**
* Perform some basic functional tests on the driver;
* make sure we can collect data from the sensor in polled
* and automatic modes.
*/
void
test()
{
PX4_INFO("PASS");
}
/**
* Reset the driver.
*/
void
reset()
{
DevHandle h;
DevMgr::getHandle(GPSSIM_DEVICE_PATH, h);
if (!h.isValid()) {
PX4_ERR("failed ");
}
if (h.ioctl(SENSORIOCRESET, 0) < 0) {
PX4_ERR("reset failed");
}
}
/**
* Print the status of the driver.
*/
void
info()
{
if (g_dev == nullptr) {
PX4_ERR("gpssim not running");
return;
}
g_dev->print_info();
}
void
usage(const char *reason)
{
if (reason) {
PX4_WARN("%s", reason);
}
PX4_INFO("usage:");
PX4_INFO("gpssim {start|stop|test|reset|status|set}");
PX4_INFO(" [-d /dev/ttyS0-n][-f (for enabling fake)][-s (to enable sat info)]");
PX4_INFO(" [-t # (for setting fix_type)][-n # (for setting # satellites)][-m # (for setting noise multiplier [scalar] for normal distribution)]");
}
} // namespace
int
gpssim_main(int argc, char *argv[])
{
// set to default
const char *device_name = GPS_DEFAULT_UART_PORT;
bool fake_gps = false;
bool enable_sat_info = false;
int fix_type = -1;
int num_sat = -1;
int noise_multiplier = 0;
// check for optional arguments
int ch;
int myoptind = 1;
const char *myoptarg = nullptr;
while ((ch = px4_getopt(argc, argv, "d:fst:n:m:", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
case 'd':
device_name = myoptarg;
PX4_INFO("Using device %s", device_name);
break;
case 'f':
fake_gps = true;
PX4_INFO("Using fake GPS");
break;
case 's':
enable_sat_info = true;
PX4_INFO("Satellite info enabled");
break;
case 't':
fix_type = atoi(myoptarg);
PX4_INFO("Setting fix_type to %d", fix_type);
break;
case 'n':
num_sat = atoi(myoptarg);
PX4_INFO("Setting number of satellites to %d", num_sat);
break;
case 'm':
noise_multiplier = atoi(myoptarg);
PX4_INFO("Setting noise multiplier to %d", noise_multiplier);
break;
default:
PX4_WARN("Unknown option!");
}
}
if (myoptind >= argc) {
gpssim::usage("not enough arguments supplied");
return 1;
}
/*
* Start/load the driver.
*/
if (!strcmp(argv[myoptind], "start")) {
if (g_dev != nullptr) {
PX4_WARN("already started");
return 0;
}
gpssim::start(device_name, fake_gps, enable_sat_info, fix_type, num_sat, noise_multiplier);
return 0;
}
/* The following need gpssim running. */
if (g_dev == nullptr) {
PX4_WARN("not running");
return 1;
}
if (!strcmp(argv[myoptind], "stop")) {
gpssim::stop();
}
/*
* Test the driver/device.
*/
if (!strcmp(argv[myoptind], "test")) {
gpssim::test();
}
/*
* Reset the driver.
*/
if (!strcmp(argv[myoptind], "reset")) {
gpssim::reset();
}
/*
* Print driver status.
*/
if (!strcmp(argv[myoptind], "status")) {
gpssim::info();
}
/*
* Set parameters
*/
if (!strcmp(argv[myoptind], "set")) {
g_dev->set(fix_type, num_sat, noise_multiplier);
}
return 0;
}
+96
View File
@@ -0,0 +1,96 @@
/****************************************************************************
*
* Copyright (c) 2012-2015 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.
*
****************************************************************************/
/**
* @file ubx.cpp
*
* U-Blox protocol implementation. Following u-blox 6/7/8 Receiver Description
* including Prototol Specification.
*
* @author Thomas Gubler <thomasgubler@student.ethz.ch>
* @author Julian Oes <joes@student.ethz.ch>
* @author Anton Babushkin <anton.babushkin@me.com>
*
* @author Hannes Delago
* (rework, add ubx7+ compatibility)
*
* @see http://www.u-blox.com/images/downloads/Product_Docs/u-blox6_ReceiverDescriptionProtocolSpec_%28GPS.G6-SW-10018%29.pdf
* @see http://www.u-blox.com/images/downloads/Product_Docs/u-bloxM8_ReceiverDescriptionProtocolSpec_%28UBX-13003221%29_Public.pdf
*/
#include <assert.h>
#include <math.h>
#include <poll.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <systemlib/err.h>
#include <uORB/uORB.h>
#include <uORB/topics/vehicle_gps_position.h>
#include <uORB/topics/satellite_info.h>
#include <drivers/drv_hrt.h>
#include "ubx_sim.h"
#include <simulator/simulator.h>
#define UBX_CONFIG_TIMEOUT 200 // ms, timeout for waiting ACK
#define UBX_PACKET_TIMEOUT 2 // ms, if now data during this delay assume that full update received
#define UBX_WAIT_BEFORE_READ 20 // ms, wait before reading to save read() calls
#define DISABLE_MSG_INTERVAL 1000000 // us, try to disable message with this interval
UBX::UBX(const int &fd, struct vehicle_gps_position_s *gps_position, struct satellite_info_s *satellite_info) :
_fd(fd),
_gps_position(gps_position),
_satellite_info(satellite_info),
{
}
UBX::~UBX()
{
}
int UBX_SIM::configure(unsigned &baudrate)
{
return 0;
}
int // -1 = error, 0 = no message handled, 1 = message handled, 2 = sat info message handled
UBX_SIM::receive(const unsigned timeout)
{
/* copy data from simulator here */
usleep(1000000);
return 1;
}
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2015 PX4 Development Team. All rights reserved.
* Copyright (c) 2012, 2013, 2014 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
@@ -32,41 +32,26 @@
****************************************************************************/
/**
* @file param.h
*
* Global flash based parameter store.
*
* This provides the mechanisms to interface to the PX4
* parameter system but replace the IO with non file based flash
* i/o routines. So that the code my be implemented on a SMALL memory
* foot print device.
* @file ubx_sim.h
*
*/
#ifndef _SYSTEMLIB_FLASHPARAMS_FLASHPARAMS_H
#define _SYSTEMLIB_FLASHPARAMS_FLASHPARAMS_H
#ifndef UBX_SIM_H_
#define UBX_SIM_H_
#include <stdint.h>
#include <stdbool.h>
#include <sys/types.h>
#include "systemlib/uthash/utarray.h"
class UBX_SIM
{
public:
UBX_SIM(const int &fd, struct vehicle_gps_position_s *gps_position, struct satellite_info_s *satellite_info);
~UBX_SIM();
int receive(const unsigned timeout);
int configure(unsigned &baudrate);
__BEGIN_DECLS
private:
int _fd;
struct vehicle_gps_position_s *_gps_position;
struct satellite_info_s *_satellite_info;
bool _enable_sat_info;
};
/*
* When using the flash based parameter store we have to force
* the param_values and 2 functions to be global
*/
#define FLASH_PARAMS_EXPOSE __EXPORT
__EXPORT extern UT_array *param_values;
__EXPORT int param_set_external(param_t param, const void *val, bool mark_saved, bool notify_changes);
__EXPORT const void *param_get_value_ptr_external(param_t param);
/* The interface hooks to the Flash based storage. The caller is responsible for locking */
__EXPORT int flash_param_save(void);
__EXPORT int flash_param_load(void);
__EXPORT int flash_param_import(void);
__END_DECLS
#endif /* _SYSTEMLIB_FLASHPARAMS_FLASHPARAMS_H */
#endif /* UBX_SIM_H_ */
@@ -0,0 +1,42 @@
############################################################################
#
# Copyright (c) 2015 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 drivers__gyrosim
MAIN gyrosim
STACK_MAIN 1200
SRCS
gyrosim.cpp
DEPENDS
modules__simulator
)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,35 @@
############################################################################
#
# Copyright (c) 2015 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_library(drivers__ledsim led.cpp)
target_link_libraries(drivers__ledsim PRIVATE drivers__led drivers_board)
+139
View File
@@ -0,0 +1,139 @@
/****************************************************************************
*
* Copyright (c) 2013 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.
*
****************************************************************************/
/**
* @file led.cpp
*
* LED driver.
*/
#include <px4_config.h>
#include <drivers/drv_board_led.h>
#include <stdio.h>
#include "VirtDevObj.hpp"
using namespace DriverFramework;
/*
* Ideally we'd be able to get these from up_internal.h,
* but since we want to be able to disable the NuttX use
* of leds for system indication at will and there is no
* separate switch, we need to build independent of the
* CONFIG_ARCH_LEDS configuration switch.
*/
__BEGIN_DECLS
extern void led_init();
extern void led_on(int led);
extern void led_off(int led);
extern void led_toggle(int led);
__END_DECLS
class LED : public VirtDevObj
{
public:
LED();
virtual ~LED();
virtual int init();
virtual int devIOCTL(unsigned long cmd, unsigned long arg);
protected:
virtual void _measure() {}
};
LED::LED() :
VirtDevObj("led", "/dev/ledsim", LED_BASE_DEVICE_PATH, 0)
{
// force immediate init/device registration
init();
}
LED::~LED()
{
}
int
LED::init()
{
int ret = VirtDevObj::init();
if (ret == 0) {
led_init();
}
return ret;
}
int
LED::devIOCTL(unsigned long cmd, unsigned long arg)
{
int result = OK;
switch (cmd) {
case LED_ON:
led_on(arg);
break;
case LED_OFF:
led_off(arg);
break;
case LED_TOGGLE:
led_toggle(arg);
break;
default:
result = VirtDevObj::devIOCTL(cmd, arg);
}
return result;
}
namespace
{
LED *gLED;
}
void
drv_led_start(void)
{
if (gLED == nullptr) {
gLED = new LED;
if (gLED != nullptr) {
gLED->init();
}
}
}
+2 -2
View File
@@ -54,8 +54,8 @@
#include <drivers/drv_mag.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_rc_input.h>
#include <systemlib/perf_counter.h>
#include <systemlib/battery.h>
#include <perf/perf_counter.h>
#include <battery/battery.h>
#include <uORB/uORB.h>
#include <uORB/topics/optical_flow.h>
#include <uORB/topics/distance_sensor.h>
+1 -1
View File
@@ -38,7 +38,7 @@
*
* @author Mohamed Abdelkader <mohamedashraf123@gmail.com>
*/
#include <systemlib/param/param.h>
#include <parameters/param.h>
/**
* Simulator UDP port
+1 -2
View File
@@ -41,6 +41,5 @@ px4_add_module(
syslink_params.c
syslink.c
DEPENDS
platforms__common
)
# vim: set noet ft=cmake fenc=utf-8 ff=unix :
+1 -1
View File
@@ -35,7 +35,7 @@
#include <stdint.h>
#include <systemlib/battery.h>
#include <battery/battery.h>
#include <drivers/device/device.h>
#include <drivers/device/ringbuffer.h>
+1 -1
View File
@@ -40,7 +40,7 @@
*/
#include <nuttx/config.h>
#include <systemlib/param/param.h>
#include <parameters/param.h>
/**

Some files were not shown because too many files have changed in this diff Show More