SERVOPOS and variable for the pin

jl-bot

New Member
@ technical

Hi,

Picaxe can drive many servos. It is excellent. (e.g. the kit "caterpillar" with 18X1 and 8 servos !)

The command SERVO accept a variable which specifies the i/o pin
but not the command SERVOPOS, only a constant.

In the program, with 8 servos it is necessary to create 8 different gosub with SERVOPOS 0, ... SERVOPOS 1,.....
SERVOPOS 2,..... SERVOPOS 3,.... etc SERVOPOS 7,....

with SERVO one gosub is sufficient SERVO x,..... (x =0 to 7 ) syntax OK

In the manual:
" The ‘servo’ command initialises the pin for servo operation and starts the timer.
Once a pin has been initialised, it is recommended to use the ‘servopos’
command to adjust position. This prevents resetting of the timer, which could
cause ‘jitter’ "
(Yes I note this behaviour with my robot )

SERVOPOS is important for good program.

In the future update, can you modify SERVOPOS for it accept also a variable for the pin, if it is possible.


Thanks

(sorry for my english language)
 

Technical

Technical Support
Staff member
This is due to the firmware style and can't be changed, but on later chips like the X2 parts you can already use variables for the pin with servopos.
 

westaust55

Moderator
If you have 8 separate GOSUB calls for SERVOPOS you may be able to restructure with the ON...GOSUB command

As incomplete code for the concept:

Code:
SYMBOL ServoPin = b5
SYMBOL Position  = b6

Main:
; here determine with servo pin number to call in the range 0 to 7 for the 8 possibilities
; and define the new servo position - here put in variable b6

ON ServoPin GOSUB Servo0, Servo1, Servo2, Servo3, Servo4, Servo5, Servo6, Servo7

; do other "stuff"
	GOTO Main

Servo0:
	Servopos 0, b6
	RETURN
Servo1:
	Servopos 1, b6
	RETURN
Servo2:
	Servopos 2, b6
	RETURN
Servo3:
	Servopos 3, b6
	RETURN
Servo4:
	Servopos 4, b6
	RETURN
Servo5:
	Servopos 5, b6
	RETURN
Servo6:
	Servopos 6, b6
	RETURN
Servo7:
	Servopos 7, b6
	RETURN
Still needs 8 subroutines but only one program call based upon a ServoPin number
 

inglewoodpete

Senior Member
A variation on a theme. The following subroutine code is taken directly from the servo driver of a robotic "person".

Note the subtle difference from WA55's version.

WA55: On <servo> GoSub <label> 'Execution returns to the following statement
IWP: On <servo> GoTo <label> 'Whole block of code is treated as a single subroutine.

Code:
Symbol	ServoOffset	= b2	'>w1	servo routines
Symbol	NewPos		= b4	'>w2	servo routines
'
' *** SetServo - Set New Servo Position ********
'
'	Entry:	ServoOffset (0-4 for up to 5 Servos), NewPos (required new position)
'		Note: All servo pins of PICAXE must have previously been initialised
'		Also that the order does not necessarily match to logical pin numbers
'	Exit:	All registers preserved
'
SetServo:On ServoOffset Goto SrvRArm, SrvLArm, SrvNeck, SrvWaist, SrvEyes
	Return			'Any other values
SrvLArm:	ServoPos LArm, NewPos
	Return
SrvRArm:	ServoPos RArm, NewPos
	Return
SrvNeck:	ServoPos Neck, NewPos
	Return
SrvWaist:	ServoPos Waist, NewPos
	Return
SrvEyes:	ServoPos Eyes, NewPos
	Return
 
Last edited:

jl-bot

New Member
Thanks for the two solutions with olds picaxe

I have tested with 28X2 (simulate) :
"SERVOPOS variable, position " is OK

but:
"SERVOPOS variable, OFF" -----> error syntax
"SERVOPOS B.3, OFF " -----> error syntax
"SERVOPOS 3, OFF " -----> error syntax
and also with other pins B.

with 18M2:

"SERVOPOS variable, position" is OK

"SERVOPOS variable, OFF " --------> error syntax
"SERVOPOS B.3, OFF " is OK and also with other pin B.
"SERVOPOS 3, OFF" is OK and also with other pin B.
 
Top