PX4 Firmware
PX4 Autopilot Software http://px4.io
PWMSim.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 #pragma once
35 
36 #include <drivers/device/device.h>
37 #include <drivers/drv_hrt.h>
38 #include <drivers/drv_mixer.h>
39 #include <drivers/drv_pwm_output.h>
41 #include <px4_platform_common/px4_config.h>
42 #include <px4_platform_common/module.h>
43 #include <px4_platform_common/tasks.h>
44 #include <px4_platform_common/time.h>
46 
47 class PWMSim : public cdev::CDev, public ModuleBase<PWMSim>, public OutputModuleInterface
48 {
49 public:
50  PWMSim(bool hil_mode_enabled);
51 
52  /** @see ModuleBase */
53  static int task_spawn(int argc, char *argv[]);
54 
55  /** @see ModuleBase */
56  static int custom_command(int argc, char *argv[]);
57 
58  /** @see ModuleBase */
59  static int print_usage(const char *reason = nullptr);
60 
61  /** @see ModuleBase::print_status() */
62  int print_status() override;
63 
64  void Run() override;
65 
66  int ioctl(device::file_t *filp, int cmd, unsigned long arg) override;
67 
68  bool updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS],
69  unsigned num_outputs, unsigned num_control_groups_updated) override;
70 
71 private:
72  static constexpr uint16_t PWM_SIM_DISARMED_MAGIC = 900;
73  static constexpr uint16_t PWM_SIM_FAILSAFE_MAGIC = 600;
74  static constexpr uint16_t PWM_SIM_PWM_MIN_MAGIC = 1000;
75  static constexpr uint16_t PWM_SIM_PWM_MAX_MAGIC = 2000;
76 
79 
80 };
81 
static constexpr uint16_t PWM_SIM_PWM_MIN_MAGIC
Definition: PWMSim.hpp:74
static int print_usage(const char *reason=nullptr)
Definition: PWMSim.cpp:279
PWMSim(bool hil_mode_enabled)
Definition: PWMSim.cpp:42
int ioctl(device::file_t *filp, int cmd, unsigned long arg) override
Perform an ioctl operation on the device.
Definition: PWMSim.cpp:90
static constexpr uint16_t PWM_SIM_PWM_MAX_MAGIC
Definition: PWMSim.hpp:75
High-resolution timer with callouts and timekeeping.
static constexpr int MAX_ACTUATORS
static int custom_command(int argc, char *argv[])
Definition: PWMSim.cpp:268
Mixer ioctl interfaces.
static constexpr uint16_t PWM_SIM_DISARMED_MAGIC
Definition: PWMSim.hpp:72
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition: uORB.h:87
Abstract class for any character device.
Definition: CDev.hpp:58
Drive scheduling based on subscribed actuator controls topics (via uORB callbacks) ...
MixingOutput _mixing_output
Definition: PWMSim.hpp:77
static int task_spawn(int argc, char *argv[])
Definition: PWMSim.cpp:236
int print_status() override
Definition: PWMSim.cpp:273
Base class for an output module.
void Run() override
Definition: PWMSim.cpp:57
uORB::Subscription _parameter_update_sub
Definition: PWMSim.hpp:78
bool updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS], unsigned num_outputs, unsigned num_control_groups_updated) override
Callback to update the (physical) actuator outputs in the driver.
Definition: PWMSim.cpp:81
static constexpr uint16_t PWM_SIM_FAILSAFE_MAGIC
Definition: PWMSim.hpp:73
This handles the mixing, arming/disarming and all subscriptions required for that.