Gramps
Senior Member
Good morning,
My old workhorse code has suddenly started to show a syntax error at line 45.
What in the world is a "rtxd"?
Perhaps a copy and paste error?
code:
'Shadow-Bot feedback control code with limits the best one!!!
#picaxe 28x2
#no_data
#no_table
symbol DEADZONE = 4 ; Switch motor off (Make as small as practical)
symbol SLOWZONE = 12 ; Slow motor down (NB: May depend on motor speed ! )
symbol MotorSpeed = w4 ; (To replace the "300" in the present PWMOUT code)
symbol LOOPGAIN = 33 ; i.e. MAXPWMVALUE / SLOWZONE (= 399 / 12)
symbol PWMPERIOD = 199 ; Equivalent Max Duty Cycle is 799
symbol xb0 = b0 ' reserved for bit variables
symbol bReverseForward=bit1 ' 0=reverse,1 =forward
symbol bMotorState=bit0 ' 0=off,1=on
symbol REVERSE_=0
symbol FORWARD_=1
Symbol desired_pot_value = b1
Symbol feedback_pot_value = b3
Symbol diff=b4
Symbol desired_pot = 13 'B.5
Symbol feedback_pot = 11'B.4
Symbol MOTOR = B.0' Energize PWM
Symbol Direction = B.7
Symbol MAXPWMVALUE = 399
Symbol bSlowState=bit2
Symbol old_feedback_value= b5
Symbol old_desired_value= b6
Symbol ENDSTOP_A = 35 ; desired_pot MINimum value
Symbol ENDSTOP_C = 210 ; desired_pot MAXimum value
;Lower shoulder min=35 max=210
;Upper shoulder min=?? max=???
Main:
Readadc Desired_pot, desired_pot_value
Desired_pot_value = Desired_pot_value MIN ENDSTOP_A MAX ENDSTOP_C
'sertxd (#desired_pot_value," ",#b1,13,10)
Readadc feedback_pot, feedback_pot_value
' sertxd (#feedback_pot_value," ",#b3,13,10)
'sesertxd("Desired/Feedback: ",#desired_pot_value," ",#feedback_pot_value,13,10)
;endif
if desired_pot_value > feedback_pot_value then
diff=desired_pot_value - feedback_pot_value
else
diff=feedback_pot_value - desired_pot_value
endif
rtxd("Desired/Feedback: ",#desired_pot_value," ",#feedback_pot_value,13,10)
If old_feedback_value<>feedback_pot_value or old_desired_value<> desired_pot_value then
old_feedback_value=feedback_pot_value
old_desired_value=desired_pot_value
if diff > DEADZONE then
MotorSpeed = diff * LOOPGAIN max MAXPWMVALUE ; Limits speed outside of SLOWZONE
if desired_pot_value > feedback_pot_value then
high Direction ; Set forward direction
else
low Direction ; Set reverse direction
endif
pwmout MOTOR , PWMPERIOD , MotorSpeed ; Slows motor within SLOWZONE
else
pwmout MOTOR , OFF ; STOP
bMotorState=0 ; Not sure what these do (now)
bSlowState = 0 ;
endif
goto main
My old workhorse code has suddenly started to show a syntax error at line 45.
What in the world is a "rtxd"?
Perhaps a copy and paste error?
code:
'Shadow-Bot feedback control code with limits the best one!!!
#picaxe 28x2
#no_data
#no_table
symbol DEADZONE = 4 ; Switch motor off (Make as small as practical)
symbol SLOWZONE = 12 ; Slow motor down (NB: May depend on motor speed ! )
symbol MotorSpeed = w4 ; (To replace the "300" in the present PWMOUT code)
symbol LOOPGAIN = 33 ; i.e. MAXPWMVALUE / SLOWZONE (= 399 / 12)
symbol PWMPERIOD = 199 ; Equivalent Max Duty Cycle is 799
symbol xb0 = b0 ' reserved for bit variables
symbol bReverseForward=bit1 ' 0=reverse,1 =forward
symbol bMotorState=bit0 ' 0=off,1=on
symbol REVERSE_=0
symbol FORWARD_=1
Symbol desired_pot_value = b1
Symbol feedback_pot_value = b3
Symbol diff=b4
Symbol desired_pot = 13 'B.5
Symbol feedback_pot = 11'B.4
Symbol MOTOR = B.0' Energize PWM
Symbol Direction = B.7
Symbol MAXPWMVALUE = 399
Symbol bSlowState=bit2
Symbol old_feedback_value= b5
Symbol old_desired_value= b6
Symbol ENDSTOP_A = 35 ; desired_pot MINimum value
Symbol ENDSTOP_C = 210 ; desired_pot MAXimum value
;Lower shoulder min=35 max=210
;Upper shoulder min=?? max=???
Main:
Readadc Desired_pot, desired_pot_value
Desired_pot_value = Desired_pot_value MIN ENDSTOP_A MAX ENDSTOP_C
'sertxd (#desired_pot_value," ",#b1,13,10)
Readadc feedback_pot, feedback_pot_value
' sertxd (#feedback_pot_value," ",#b3,13,10)
'sesertxd("Desired/Feedback: ",#desired_pot_value," ",#feedback_pot_value,13,10)
;endif
if desired_pot_value > feedback_pot_value then
diff=desired_pot_value - feedback_pot_value
else
diff=feedback_pot_value - desired_pot_value
endif
rtxd("Desired/Feedback: ",#desired_pot_value," ",#feedback_pot_value,13,10)
If old_feedback_value<>feedback_pot_value or old_desired_value<> desired_pot_value then
old_feedback_value=feedback_pot_value
old_desired_value=desired_pot_value
if diff > DEADZONE then
MotorSpeed = diff * LOOPGAIN max MAXPWMVALUE ; Limits speed outside of SLOWZONE
if desired_pot_value > feedback_pot_value then
high Direction ; Set forward direction
else
low Direction ; Set reverse direction
endif
pwmout MOTOR , PWMPERIOD , MotorSpeed ; Slows motor within SLOWZONE
else
pwmout MOTOR , OFF ; STOP
bMotorState=0 ; Not sure what these do (now)
bSlowState = 0 ;
endif
goto main