From 3443a7817d2d1ef641b0e5a64fb2a915cbe9155d Mon Sep 17 00:00:00 2001 From: "deweibel@gmail.com" Date: Thu, 27 Jan 2011 18:16:22 +0000 Subject: [PATCH] Add reversing for PWM outputs in angle_to_pwm case. git-svn-id: https://arducopter.googlecode.com/svn/trunk@1566 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/RC_Channel/RC_Channel.cpp | 23 +++++++++++++++++++---- libraries/RC_Channel/RC_Channel.h | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libraries/RC_Channel/RC_Channel.cpp b/libraries/RC_Channel/RC_Channel.cpp index 954ad1601f..378cbc973e 100644 --- a/libraries/RC_Channel/RC_Channel.cpp +++ b/libraries/RC_Channel/RC_Channel.cpp @@ -40,6 +40,13 @@ RC_Channel::set_reverse(bool reverse) else _reverse = 1; } +bool +RC_Channel::get_reverse(void) +{ + if (_reverse==-1) return 1; + else return 0; +} + void RC_Channel::set_filter(bool filter) { @@ -179,10 +186,18 @@ RC_Channel::pwm_to_angle() int16_t RC_Channel::angle_to_pwm() { - if(servo_out < 0) - return ((long)servo_out * (long)(radio_max - radio_trim)) / (long)_high; - else - return ((long)servo_out * (long)(radio_trim - radio_min)) / (long)_high; + if(_reverse == -1) + { + if(servo_out < 0) + return ( -1 * ((long)servo_out * (long)(radio_max - radio_trim)) / (long)_high); + else + return ( -1 * ((long)servo_out * (long)(radio_trim - radio_min)) / (long)_high); + } else { + if(servo_out > 0) + return ((long)servo_out * (long)(radio_max - radio_trim)) / (long)_high; + else + return ((long)servo_out * (long)(radio_trim - radio_min)) / (long)_high; + } //return (((float)servo_out / (float)_high) * (float)(radio_max - radio_trim)); //return (((float)servo_out / (float)_high) * (float)(radio_trim - radio_min)); diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index 37ca3713bb..00653bc764 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -52,6 +52,7 @@ class RC_Channel{ void set_range(int low, int high); void set_angle(int angle); void set_reverse(bool reverse); + bool get_reverse(void); // read input from APM_RC - create a control_in value void set_pwm(int pwm);