From de7aa60f4b31e1ce95e52041c78c717372a828e7 Mon Sep 17 00:00:00 2001 From: Simon Wilks Date: Wed, 5 Sep 2012 11:41:34 +0200 Subject: [PATCH 1/6] Fix the RC mappings. The value of the RC mapping parameters are mixed up resulting in the wrong parameter handle index values being used when attempting to read the corresponding RC channels. Currently giving throttle input on Mode 2 TXs will result in a roll input, etc. --- apps/sensors/sensor_params.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/sensors/sensor_params.c b/apps/sensors/sensor_params.c index 221711c7f2..16d4e07fb6 100644 --- a/apps/sensors/sensor_params.c +++ b/apps/sensors/sensor_params.c @@ -101,8 +101,8 @@ PARAM_DEFINE_INT32(RC_TYPE, 1); // 1 = FUTABA /* default is conversion factor for the PX4IO / PX4IOAR board, the factor for PX4FMU standalone is different */ PARAM_DEFINE_FLOAT(BAT_V_SCALING, (3.3f * 52.0f / 5.0f / 4095.0f)); -PARAM_DEFINE_INT32(RC_MAP_ROLL, 1); -PARAM_DEFINE_INT32(RC_MAP_PITCH, 2); -PARAM_DEFINE_INT32(RC_MAP_THROTTLE, 3); +PARAM_DEFINE_INT32(RC_MAP_THROTTLE, 1); +PARAM_DEFINE_INT32(RC_MAP_ROLL, 2); +PARAM_DEFINE_INT32(RC_MAP_PITCH, 3); PARAM_DEFINE_INT32(RC_MAP_YAW, 4); PARAM_DEFINE_INT32(RC_MAP_MODE_SW, 5); From ccafa0e982bfeb7c6cfcf9ad45d32946663c405f Mon Sep 17 00:00:00 2001 From: Simon Wilks Date: Wed, 5 Sep 2012 11:53:29 +0200 Subject: [PATCH 2/6] Revert "Fix the RC mappings." This reverts commit de7aa60f4b31e1ce95e52041c78c717372a828e7. --- apps/sensors/sensor_params.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/sensors/sensor_params.c b/apps/sensors/sensor_params.c index 16d4e07fb6..221711c7f2 100644 --- a/apps/sensors/sensor_params.c +++ b/apps/sensors/sensor_params.c @@ -101,8 +101,8 @@ PARAM_DEFINE_INT32(RC_TYPE, 1); // 1 = FUTABA /* default is conversion factor for the PX4IO / PX4IOAR board, the factor for PX4FMU standalone is different */ PARAM_DEFINE_FLOAT(BAT_V_SCALING, (3.3f * 52.0f / 5.0f / 4095.0f)); -PARAM_DEFINE_INT32(RC_MAP_THROTTLE, 1); -PARAM_DEFINE_INT32(RC_MAP_ROLL, 2); -PARAM_DEFINE_INT32(RC_MAP_PITCH, 3); +PARAM_DEFINE_INT32(RC_MAP_ROLL, 1); +PARAM_DEFINE_INT32(RC_MAP_PITCH, 2); +PARAM_DEFINE_INT32(RC_MAP_THROTTLE, 3); PARAM_DEFINE_INT32(RC_MAP_YAW, 4); PARAM_DEFINE_INT32(RC_MAP_MODE_SW, 5); From 37163011fc752e40ee712d4c945c8393538f2708 Mon Sep 17 00:00:00 2001 From: Simon Wilks Date: Mon, 24 Sep 2012 23:36:21 +0200 Subject: [PATCH 3/6] Use the update rate parameter provided and not the default. --- UPDATE_GIT.sh | 8 ++++++++ nuttx/configs/px4fmu/src/up_pwm_servo.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100755 UPDATE_GIT.sh diff --git a/UPDATE_GIT.sh b/UPDATE_GIT.sh new file mode 100755 index 0000000000..f6cd75b7c5 --- /dev/null +++ b/UPDATE_GIT.sh @@ -0,0 +1,8 @@ +#/bin/sh + +git fetch upstream +# Fetches any new changes from the original repo + +git merge upstream/master +# Merges any changes fetched into your working files + diff --git a/nuttx/configs/px4fmu/src/up_pwm_servo.c b/nuttx/configs/px4fmu/src/up_pwm_servo.c index adb9b50308..d278da55c3 100644 --- a/nuttx/configs/px4fmu/src/up_pwm_servo.c +++ b/nuttx/configs/px4fmu/src/up_pwm_servo.c @@ -179,7 +179,7 @@ static void pwm_timer_set_rate(unsigned timer, unsigned rate) { /* configure the timer to update at the desired rate */ - rARR(timer) = 1000000 / pwm_update_rate; + rARR(timer) = 1000000 / rate; /* generate an update event; reloads the counter and all registers */ rEGR(timer) = GTIM_EGR_UG; From 7a5ac6892e68c14b77ba6e3db3fd7e0b9f1c79c6 Mon Sep 17 00:00:00 2001 From: Simon Wilks Date: Thu, 27 Sep 2012 23:36:56 +0200 Subject: [PATCH 4/6] Support custom PWM update rates Rates of 50 to 400 can be specified using the -u parameter with the fmu command in the startup script. --- apps/px4/fmu/fmu.cpp | 64 +++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/apps/px4/fmu/fmu.cpp b/apps/px4/fmu/fmu.cpp index a9aab04320..d8f824c53d 100644 --- a/apps/px4/fmu/fmu.cpp +++ b/apps/px4/fmu/fmu.cpp @@ -66,7 +66,6 @@ #include #include - class FMUServo : public device::CDev { public: @@ -75,7 +74,7 @@ public: MODE_4PWM, MODE_NONE }; - FMUServo(Mode mode); + FMUServo(Mode mode, int update_rate); ~FMUServo(); virtual int ioctl(struct file *filp, int cmd, unsigned long arg); @@ -86,6 +85,7 @@ private: static const unsigned _max_actuators = 4; Mode _mode; + int _update_rate; int _task; int _t_actuators; int _t_armed; @@ -115,9 +115,10 @@ FMUServo *g_servo; } // namespace -FMUServo::FMUServo(Mode mode) : +FMUServo::FMUServo(Mode mode, int update_rate) : CDev("fmuservo", PWM_OUTPUT_DEVICE_PATH), _mode(mode), + _update_rate(update_rate), _task(-1), _t_actuators(-1), _t_armed(-1), @@ -199,6 +200,8 @@ FMUServo::task_main() /* multi-port as 4 PWM outs */ /* XXX magic numbers */ up_pwm_servo_init(0xf); + /* set the update rate for 4 PWM mode only for now */ + up_pwm_servo_set_rate(_update_rate); break; case MODE_NONE: @@ -208,7 +211,9 @@ FMUServo::task_main() /* subscribe to objects that we are interested in watching */ _t_actuators = orb_subscribe(ORB_ID_VEHICLE_ATTITUDE_CONTROLS); - orb_set_interval(_t_actuators, 20); /* 50Hz update rate */ + /* convert the update rate in hz to milliseconds, rounding down if necessary */ + int update_rate_in_ms = int(1000 / _update_rate); + orb_set_interval(_t_actuators, update_rate_in_ms); _t_armed = orb_subscribe(ORB_ID(actuator_armed)); orb_set_interval(_t_armed, 200); /* 5Hz update rate */ @@ -444,7 +449,7 @@ enum PortMode { PortMode g_port_mode; int -fmu_new_mode(PortMode new_mode) +fmu_new_mode(PortMode new_mode, int update_rate) { int fd; int ret = OK; @@ -511,7 +516,7 @@ fmu_new_mode(PortMode new_mode) /* create new PWM driver if required */ if (servo_mode != FMUServo::MODE_NONE) { - g_servo = new FMUServo(servo_mode); + g_servo = new FMUServo(servo_mode, update_rate); if (g_servo == nullptr) { ret = -ENOMEM; @@ -585,6 +590,7 @@ int fmu_main(int argc, char *argv[]) { PortMode new_mode = PORT_MODE_UNSET; + int pwm_update_rate_in_hz = 50; if (!strcmp(argv[1], "test")) test(); @@ -597,24 +603,40 @@ fmu_main(int argc, char *argv[]) * * XXX use getopt? */ - if (!strcmp(argv[1], "mode_gpio")) { - new_mode = PORT_FULL_GPIO; + for (int i = 1; i < argc; i++) { /* argv[0] is "fmu" */ + if (!strcmp(argv[i], "mode_gpio")) { + new_mode = PORT_FULL_GPIO; - } else if (!strcmp(argv[1], "mode_serial")) { - new_mode = PORT_FULL_SERIAL; + } else if (!strcmp(argv[i], "mode_serial")) { + new_mode = PORT_FULL_SERIAL; - } else if (!strcmp(argv[1], "mode_pwm")) { - new_mode = PORT_FULL_PWM; + } else if (!strcmp(argv[i], "mode_pwm")) { + new_mode = PORT_FULL_PWM; - } else if (!strcmp(argv[1], "mode_gpio_serial")) { - new_mode = PORT_GPIO_AND_SERIAL; + } else if (!strcmp(argv[i], "mode_gpio_serial")) { + new_mode = PORT_GPIO_AND_SERIAL; - } else if (!strcmp(argv[1], "mode_pwm_serial")) { - new_mode = PORT_PWM_AND_SERIAL; + } else if (!strcmp(argv[i], "mode_pwm_serial")) { + new_mode = PORT_PWM_AND_SERIAL; - } else if (!strcmp(argv[1], "mode_pwm_gpio")) { - new_mode = PORT_PWM_AND_GPIO; - } + } else if (!strcmp(argv[i], "mode_pwm_gpio")) { + new_mode = PORT_PWM_AND_GPIO; + } + + /* look for the optional pwm update rate for the supported modes */ + if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--update-rate") == 0) { + if (new_mode == PORT_FULL_PWM || new_mode == PORT_PWM_AND_SERIAL || new_mode == PORT_PWM_AND_GPIO) { + if (argc > i + 1) { + pwm_update_rate_in_hz = atoi(argv[i + 1]); + } else { + fprintf(stderr, "missing argument for pwm update rate (-u)\n"); + return 1; + } + } else { + fprintf(stderr, "pwm update rate currently only supported for mode_pwm, mode_gpio_serial, mode_pwm_gpio\n"); + } + } + } /* was a new mode set? */ if (new_mode != PORT_MODE_UNSET) { @@ -624,12 +646,12 @@ fmu_main(int argc, char *argv[]) return OK; /* switch modes */ - return fmu_new_mode(new_mode); + return fmu_new_mode(new_mode, pwm_update_rate_in_hz); } /* test, etc. here */ fprintf(stderr, "FMU: unrecognised command, try:\n"); - fprintf(stderr, " mode_gpio, mode_serial, mode_pwm, mode_gpio_serial, mode_pwm_serial, mode_pwm_gpio\n"); + fprintf(stderr, " mode_gpio, mode_serial, mode_pwm [-r pwm_update_rate_in_hz], mode_gpio_serial, mode_pwm_serial, mode_pwm_gpio\n"); return -EINVAL; } From b02a5a9eb960a815eeab4ab30e86f3d2bd8e8b12 Mon Sep 17 00:00:00 2001 From: Simon Wilks Date: Thu, 27 Sep 2012 23:44:05 +0200 Subject: [PATCH 5/6] I don't want to track this script. --- UPDATE_GIT.sh | 8 -------- 1 file changed, 8 deletions(-) delete mode 100755 UPDATE_GIT.sh diff --git a/UPDATE_GIT.sh b/UPDATE_GIT.sh deleted file mode 100755 index f6cd75b7c5..0000000000 --- a/UPDATE_GIT.sh +++ /dev/null @@ -1,8 +0,0 @@ -#/bin/sh - -git fetch upstream -# Fetches any new changes from the original repo - -git merge upstream/master -# Merges any changes fetched into your working files - From 4933d1dbbd8146ec548168fb9b855009107078ca Mon Sep 17 00:00:00 2001 From: Simon Wilks Date: Fri, 28 Sep 2012 08:37:24 +0200 Subject: [PATCH 6/6] Only provide update rate mod support to modes supporting 4 PWM channels --- apps/px4/fmu/fmu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/px4/fmu/fmu.cpp b/apps/px4/fmu/fmu.cpp index d8f824c53d..48d338c992 100644 --- a/apps/px4/fmu/fmu.cpp +++ b/apps/px4/fmu/fmu.cpp @@ -625,7 +625,7 @@ fmu_main(int argc, char *argv[]) /* look for the optional pwm update rate for the supported modes */ if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--update-rate") == 0) { - if (new_mode == PORT_FULL_PWM || new_mode == PORT_PWM_AND_SERIAL || new_mode == PORT_PWM_AND_GPIO) { + if (new_mode == PORT_FULL_PWM || new_mode == PORT_PWM_AND_GPIO) { if (argc > i + 1) { pwm_update_rate_in_hz = atoi(argv[i + 1]); } else { @@ -633,7 +633,7 @@ fmu_main(int argc, char *argv[]) return 1; } } else { - fprintf(stderr, "pwm update rate currently only supported for mode_pwm, mode_gpio_serial, mode_pwm_gpio\n"); + fprintf(stderr, "pwm update rate currently only supported for mode_pwm, mode_pwm_gpio\n"); } } }