RC Fail-Safe Script review

4 months 2 weeks ago - 4 months 2 weeks ago #29534908 by wstuck
Would any of the programmers out there please suggest best programming practices advice for the script I wrote below? Any suggestions or help would be appreciated.


' This script is provided "as-is", without warranty of any kind,
' expressed or implied, including but not limited to the warranties of
' merchantability, fitness for a particular purpose and
' noninfringement. In no event shall Design Ability Inc be liable for any claim,
' damages or other liability, arising from the use of the software."
' ***
' This script reads the controller Pulse Pin1 and Pin2 value
' then compares values to min and max values
' then outputs safe values
' ***
print("starting Pulse Fail-Safe... \r") ' Lets user know script is starting
' ***
top:
' Label marking the beginning of the script.
' Set known limits and values
' ***
' Pulse Ch1 min/max
pulse_min1 = 1100 ' Minimum value for Pulse Ch1
pulse_max1 = 1900 ' Maximum value for Pulse Ch1
' ***
' Pulse Ch2 min/max
pulse_min2 = 1100 ' Minimum value for Pulse Ch2
pulse_max2 = 1900 ' Maximum value for Pulse Ch2
' ***
' Pulse Ch1 and Ch2 Safe Value
pulse_safe1 = 1500 ' Safe value for Pulse Ch1
pulse_safe2 = 1500 ' Safe value for Pulse Ch2
' ***
' Read the Pulse Pin1 and Pin2 values
pulse1 = getvalue(_pic,1) 'put pulse ch1 Pin1 in variable
pulse2 = getvalue(_pic,2) 'put pulse ch2 Pin2 in variable
' ***
' If statement that looks at a user defined min and max
' and allows normal signal or outputs user defined safe values
' for Pulse In ch1 Pin1 and Pulse In ch2 Pin2.
if pulse1 > pulse_max1 then
pulse1u = pulse_safe1
else
' Otherwise, use pulse Pin1 input value
pulse1u = pulse1
end if
' ***
if pulse1 < pulse_min1 then
pulse1u = pulse_safe1
else
' Otherwise, use pulse Pin1 input value
pulse1u = pulse1
end if
' ***
if pulse2 > pulse_max2 then
pulse2u = pulse_safe2
else
' Otherwise, use pulse Pin2 input value
pulse2u = pulse2
end if
' ***
if pulse2 < pulse_min then
pulse2u = pulse_safe2
else
' Otherwise, use pulse Pin2 input value
pulse2u = pulse2
end if
' ***
' Output of If statement would be pulse1u = pulse1 value
' or a user setting if outside of min/max value pulse_safe1
' ***
' and
' ***
' Output of If statement would be pulse2u = pulse2 value
' or a user setting if outside of min/max value pulse_safe2
' ***
' Set output commands for Pulse Ch1 and Pulse Ch2
' ***
setcommand(_go,1, pulse1u) 'serial control of motor1 command with pulse user value
setcommand(_go,2,pulse2u) 'serial control of motor2 command with pulse user value
' Go To Top and Repeat Script
goto top ' Repeat indefinitely

Please Log in or Create an account to join the conversation.

Time to create page: 0.113 seconds