Array and Function Difficulties - Controlling AL5A Arm

Hey guys. I’m trying to create subroutines to control the AL5A Lynxmotion arm connected via SSC-32 to the Bot Board 2 and Basic Atom Pro. I’d like to be able to press a button (via bluetooth, which works with other code), and have the arm move into a preset position.

I’ve successfully written code to move the arm’s base to a new set location, from wherever its current location is. I’ve now tried to convert this into a function that can move all servos on the arm one after another. I decided to do this using a ‘for’ loop, so it iterates through the different servos. An array is also used to store current positions and destinations at the beginning of the function.

However, it doesn’t work! When I try to execute the function, nothing appears to happen at all. It’s as if it can’t find it or something? I really thought this code would work and have been hitting my head against the wall a bit :wink:. I tried to SEROUT to Console 1 at the beginning of the function, but that didn’t work either. Here’s all the relevant code:

[code]
; SSC32 Settings
cSSC_OUT con P8 ;Output pin for (SSC32 RX) on BotBoard (Yellow)
cSSC_BAUD con i38400 ;SSC32 BAUD rate 38400 115200

'SSC-32 Connections
PAN con 0
TILT con 1
GRIP_UD con 2
GRIP_Rot con 3
GRIP_OC con 4
ELBOWTILT con 5

'Bluetooth
BT_Input var word
ENABLEHSERIAL
SETHSERIAL1 H9600, H8DATABITS, HNOPARITY, H1STOPBITS

destinationarray var word(6)
positionarray var word(6)
armdestination var word
armposition var word
armiterator var word
routine_mode var byte ’ 0 - None = 1 = NEW
RoutinePause var word
StepSize var word
RemainderSteps var word

PanDestination var word
TiltDestination var word
GripperVertDestination var word
GripperTurnDestination var word
GripperGripDestination var word
ElbowDestination var word

PanPosition var word
TiltPosition var word
GripperVertPosition var word
GripperTurnPosition var word
GripperGripPosition var word
ElbowPosition var word

'Auto Routine Config
StepSize = 200
RoutinePause = 100

'Lifter Config (start servos at mid position)
PanPosition = 1500
TiltPosition = 1500
GripperVertPosition = 1500
GripperTurnPosition = 1500
GripperGripPosition = 1500
ElbowPosition = 1500

'Ensure pulsout commands are positive going.
low PAN
low TILT
low GRIP_UD
low GRIP_Rot
low GRIP_OC
low ELBOWTILT

main:
pause 20
HSERIN noinput,20,[BT_Input]

if (BT_Input = "t") then 
	gosub armroutine[1500,1500,1500,1500,1500,1500]
endif	

goto main

pulsearm:
'Send out the servo pulses
serout cSSC_OUT, cSSC_BAUD, “#”, dec PAN, “P”, dec PanPosition, |
“#”, dec TILT, “P”, dec TiltPosition, |
“#”, dec GRIP_UD, “P”, dec GripperVertPosition, |
“#”, dec GRIP_Rot, “P”, dec GripperTurnPosition, |
“#”, dec GRIP_OC, “P”, dec GripperGripPosition, |
“#”, dec ELBOWTILT, “P”, dec ElbowPosition, |
“#”, dec HEAVYLIFT, “P”, dec HeavyLiftPosition, 13]
pause RoutinePause
return

armroutine [PanDestination,TiltDestination,ElbowDestination,GripperVertDestination,GripperTurnDestination,GripperGripDestination]
destinationarray(0) = PanDestination
destinationarray(1) = TiltDestination
destinationarray(2) = ElbowDestination
destinationarray(3) = GripperVertDestination
destinationarray(4) = GripperTurnDestination
destinationarray(5) = GripperGripDestination
positionarray(0) = PanPosition
positionarray(1) = TiltPosition
positionarray(2) = ElbowPosition
positionarray(3) = GripperVertPosition
positionarray(4) = GripperTurnPosition
positionarray(5) = GripperGripPosition
armiterator = 0
for armiterator = 0 to 5
armdestination = destinationarray(armiterator)
armposition = positionarray(armiterator)
routine_mode = 1
if (armposition > armdestination) then
RemainderSteps = armposition - armdestination
while (RemainderSteps > StepSize)
RemainderSteps = RemainderSteps - StepSize
armposition = (armposition - StepSize)
gosub pulsearm
wend
armposition = (armposition - RemainderSteps)
gosub pulsearm
elseif (armposition < armdestination)
RemainderSteps = armdestination - armposition
while (RemainderSteps > StepSize)
RemainderSteps = RemainderSteps - StepSize
armposition = (armposition + StepSize)
gosub pulsearm
wend
armposition = (armposition + RemainderSteps)
gosub pulsearm
endif
next
routine_mode = 0
goto main[/code]

Would much appreciate any insight you may have!

Hi and Welcome,

Sorry I don’t have a lot of time to try to go through the complete program and can not test it as I don’t have a BT setup and the like. But if it were me I would break down the problem and try to localize the issue. I would have the BAP hooked up with the RS232 and hooked up to one of the debug tabs. I would add a bunch of serout s_out, i38400,“My debug stuff”, 13]
To figure out what is happening. Like did you receive data from the BT

I would put a serout right after your hserin that gave you BT_INPUT…

I would put one in the start of armroutine, which prints all of the values (which also verifies it actually made it there…

I would also place some inside your for loop, and maybe inside your while loops and then finally inside your pulsearm function.

Actually typing this debug stuff, already led to probably to your issue.

That is look at the two functions pulsearm which for example uses the variable PanPosition (as well as others).
Now look at the function armroutine. It takes the current value of PanPosition and stores it into an array positionarray(0) and later in the loop extracts it from the positionarray to a simple variable armposition and then mucks with this variable. How does the value in the variable PanPosition ever get updated?

If it were me, I would get rid of the variables PanPosition… and instead have pulsearm use the values from the positionarray. I would also get rid of the variable armposition and maybe armdestination and again simply use the values out of the array like:
positionarray(armiterator) = positionarray(armiterator) - StepSize

But then again I would probably simplify the whole thing and make use of the SSC-32. That is I would probably want all of the servos to move with each other and probably have them all reach the new position in some amount of time. So I would use the T option on the SSC-32 move command…

Good Luck
Kurt

Brilliant Kurt - thanks for noticing that error. I’m confident that will fix the problem, but will report back if I encounter any difficulties.

Hadn’t considered using the T option on the SSC-32. Looks interesting though. How would I go about programming? Would the code (see example below) be flashed on the Basic Atom Pro with everything else?

#5 P1600 #17 P750 S500 #2 P2250 T2000

I don’t see how this would connect to the SSC-32.