42 #include <px4_platform_common/px4_config.h> 43 #include <px4_platform_common/getopt.h> 44 #include <px4_platform_common/log.h> 45 #include <px4_platform_common/module.h> 52 static void usage(
const char *reason);
58 test_motor.motor_number = channel;
59 test_motor.value = value;
60 test_motor.action = value >= 0.f ? test_motor_s::ACTION_RUN : test_motor_s::ACTION_STOP;
61 test_motor.driver_instance = driver_instance;
65 test_motor_pub.publish(test_motor);
67 if (test_motor.action == test_motor_s::ACTION_STOP) {
68 PX4_INFO(
"motors stop command sent");
71 PX4_INFO(
"motor %d set to %.2f", channel, (
double)value);
75 static void usage(
const char *reason)
77 if (reason !=
nullptr) {
78 PX4_WARN(
"%s", reason);
81 PRINT_MODULE_DESCRIPTION(
83 Utility to test motors. 85 WARNING: remove all props before using this command. 88 PRINT_MODULE_USAGE_NAME("motor_test",
"command");
89 PRINT_MODULE_USAGE_COMMAND_DESCR(
"test",
"Set motor(s) to a specific output value");
90 PRINT_MODULE_USAGE_PARAM_INT(
'm', -1, 0, 7,
"Motor to test (0...7, all if not specified)",
true);
91 PRINT_MODULE_USAGE_PARAM_INT(
'p', 0, 0, 100,
"Power (0...100)",
true);
92 PRINT_MODULE_USAGE_PARAM_INT(
't', 0, 0, 100,
"Timeout in seconds (default=no timeout)",
true);
93 PRINT_MODULE_USAGE_PARAM_INT(
'i', 0, 0, 4,
"driver instance",
true);
94 PRINT_MODULE_USAGE_COMMAND_DESCR(
"stop",
"Stop all motors");
95 PRINT_MODULE_USAGE_COMMAND_DESCR(
"iterate",
"Iterate all motors starting and stopping one after the other");
104 uint8_t driver_instance = 0;
109 const char *myoptarg =
nullptr;
111 while ((ch = px4_getopt(argc, argv,
"i:m:p:t:", &myoptind, &myoptarg)) != EOF) {
115 driver_instance = (uint8_t)strtol(myoptarg,
nullptr, 0);
120 channel = (int)strtol(myoptarg,
nullptr, 0);
125 lval = strtoul(myoptarg,
nullptr, 0);
128 usage(
"value invalid");
132 value = ((float)lval) / 100.f;
136 timeout_ms = strtol(myoptarg,
nullptr, 0) * 1000;
145 bool run_test =
true;
147 if (myoptind >= 0 && myoptind < argc) {
148 if (strcmp(
"stop", argv[myoptind]) == 0) {
152 }
else if (strcmp(
"iterate", argv[myoptind]) == 0) {
155 for (
int i = 0; i < 8; ++i) {
164 }
else if (strcmp(
"test", argv[myoptind]) == 0) {
178 for (
int i = 0; i < 8; ++i) {
179 motor_test(i, value, driver_instance, timeout_ms);
184 motor_test(channel, value, driver_instance, timeout_ms);
Queued publication with queue length set as a message constant (ORB_QUEUE_LENGTH) ...
__EXPORT int motor_test_main(int argc, char *argv[])
static void usage(const char *reason)
High-resolution timer with callouts and timekeeping.
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
static void motor_test(unsigned channel, float value, uint8_t driver_instance, int timeout_ms)
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).