/**************************************************************************** * * Copyright (c) 2016 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 motor_ramp.cpp * * @author Andreas Antener * @author Roman Bapst */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "systemlib/err.h" #include "uORB/topics/actuator_controls.h" enum RampState { RAMP_INIT, RAMP_MIN, RAMP_RAMP, RAMP_WAIT }; enum Mode { RAMP, SINE, SQUARE }; static bool _thread_should_exit = false; /**< motor_ramp exit flag */ static bool _thread_running = false; /**< motor_ramp status flag */ static int _motor_ramp_task; /**< Handle of motor_ramp task / thread */ static float _ramp_time; static int _min_pwm; static int _max_pwm; static Mode _mode; static char *_mode_c; /** * motor_ramp management function. */ extern "C" __EXPORT int motor_ramp_main(int argc, char *argv[]); /** * Mainloop of motor_ramp. */ int motor_ramp_thread_main(int argc, char *argv[]); bool min_pwm_valid(unsigned pwm_value); bool max_pwm_valid(unsigned pwm_value); int set_min_pwm(int fd, unsigned long max_channels, unsigned pwm_value); int set_out(int fd, unsigned long max_channels, float output); int prepare(int fd, unsigned long *max_channels); /** * Print the correct usage. */ static void usage(const char *reason); static void usage(const char *reason) { if (reason) { PX4_ERR("%s", reason); } PRINT_MODULE_DESCRIPTION( R"DESCR_STR( ### Description Application to test motor ramp up. Before starting, make sure to stop any running attitude controller: $ mc_att_control stop $ fw_att_control stop When starting, a background task is started, runs for several seconds (as specified), then exits. Note: this command currently only supports the `/dev/pwm_output0` output. ### Example $ motor_ramp sine 1100 0.5 )DESCR_STR"); PRINT_MODULE_USAGE_NAME_SIMPLE("motor_ramp", "command"); PRINT_MODULE_USAGE_ARG("ramp|sine|square", "mode", false); PRINT_MODULE_USAGE_ARG("