Picaxe robot arm needs more speed, help please!!

JTepper

Member
hi guys (and any girls), ive been working on a picaxe robot arm code,
the problem i'm having is that the calculations required to workout the servo
angles to move the arm to any particular possition take so long thst the servo
movements are really jerky and smooth motion between 2 points is not really achievable,

originally i was using a 28x picaxe using lookup tables for sin cos and there inverses as well as squareroot.
I've now replaced this with a 28x1 with the intention of renning it at 16MHZ
(this wasnt possible with 28x because of servo command) i put the chip in the same board
and changed the resonator to 16MHZ and downloaded an identical code,
but noticed absolutelly no increase in speed when it should be 4x faster right?
am i doing somthing wrong?

ive since replaced the lookup tables with the 28x1's math functions
in search of a faster servo refresh rate and included the code for any
suggestions as to how to speed it up. So in summary I'm looking for any way to speed up the servo refresh rate involving either hardware of software....
Code:
symbol x=b0
symbol y=b1
symbol length=b2
symbol theta=w6
symbol lengthsquared=w13
symbol math=w12
symbol rotate=b15
symbol fingersadc=b7
symbol sholder=b16
symbol elbow=b17
symbol fingerscalc=b18
symbol wrist=b19
symbol fingers=b12
symbol fingercalc2=b20
servo 3,150
servo 4,150
servo 5,150
servo 6, 150
servo 7,150

setfreq m4 

main:

readadc 3,rotate
readadc 0,x        ;read x
readadc 1,y         ;   read y
readadc 2,fingersadc
;let b6=b7/20   ; potentially to help oppening fingers but romoved because it helped speed up
;x=x-b6 min 2

math= y*y                   ;calculate the length between origin and point
lengthsquared= x*x+math 
length=sqr lengthsquared

b4= y*100/length            ; calculate angle between x axis and point
gosub sine1b4 
theta=b4

b3= 62550-lengthsquared/305 ; cosine rule to calculate angle between two arm lengths
gosub cosine1b3             ; this is angle for second servo

b4= sin b3*105/length       ;sine rule to calculate angle between first arm length and strait line between 2 points

gosub sine1b4               ;this is the angle beteen first arm length and strait line between 2 pionts
b4=b4+theta                 ;ands the last thing to angle between the origin and the pint to calculate the first sevo angle

fingercalc2=fingersadc*14/51  ;i have a funny hardware setup for the figers and this sorts all that out 
fingerscalc=fingercalc2/2+100 
fingers=fingercalc2+150

elbow= 180-b3*5/6+90
sholder= 180-b4*5/6+75
wrist= fingerscalc + elbow + sholder

servopos 4,sholder
servopos 5,elbow
servopos 6,wrist
servopos 7,fingers
servopos 3,rotate
goto main

sine1b4:
lookup b4,(0,1,1,2,2,3,3,4,5,5,6,6,7,7,8,9,9,10,10,11,12,12,13,13,14,14,15,16,16,17,17,18,19,19,20,20,21,22,22,23,24,24,25,25,26,27,27,28,29,29,30,31,31,32,33,33,34,35,35,36,37,38,38,39,40,41,41,42,43,44,44,45,46,47,48,49,50,50,51,52,53,54,55,56,57,58,59,61,62,63,64,66,67,68,70,72,74,76,79,82,90),b4
return

cosine1b3:   ;first 100 values are negatives
lookup b3,(180,172,169,166,164,162,160,150,157,156,154,153,152,150,149,148,147,146,145,144,143,142,141,140,139,139,138,137,136,135,134,134,133,132,131,131,130,129,128,128,127,126,125,125,124,123,123,122,121,121,120,119,119,118,117,117,116,115,115,114,114,113,112,112,111,110,110,109,109,108,107,107,106,106,105,104,104,103,103,102,102,101,100,100,99,99,98,97,97,96,96,95,95,94,93,93,92,92,91,91,90,89,89,88,88,87,87,86,85,85,84,84,83,83,82,81,81,80,80,79,78,78,77,77,76,76,75,74,74,73,73,72,71,71,70,70,69,68,68,67,66,66,65,65,64,63,63,62,61,61,60,59,59,58,57,57,56,55,55,54,53,52,52,51,50,49,49,48,47,46,46,45,44,43,42,41,41,40,39,38,37,36,35,34,33,32,31,30,28,27,26,24,23,22,20,18,16,14,11,8,0,0,0),b3
return
on another note, the servos seem to glitch randomly, does anyone know a quick hardware remedy.

Reeally really appreciate any help im quite stuck
 
Last edited:

Peter M

Senior Member
Hi JTepper... welcome to the forum

The first line of your actual code is > setfreq m4
this will set the run frequency to internal osc at 4Mhz

See page 167 of manual 2 "setfreq"
 

Andrew Cowan

Senior Member
I seem to remeber hearing 28X1s will use the internal resonator unless told to.

However, after looking in manuals 1 and 2 I can't find this, so I am probably wrong.

A
 

MPep

Senior Member
Is the following of help?

#freq m4/m8/m16
Set the system clock frequency for 28X/40X parts.
Example: #freq m8
Also:
3) Resonator:
28X2 (optional) 4 (=16), 8(=32), or 10(=40) MHz
28X1 (optional) 16MHz
28X 4, 8 or 16MHz
28 / 28A 4MHz
The 28X1 and 28X2 have an internal resonator (4 or 8MHz) and so the external
resonator is optional. On 28A and 28X parts it is compulsary.
The 28X2 has an internal 4xPLL circuit. This multiplies the external clock speed
by 4. Therefore an external 4MHz resonator gives an actual internal operating
clock frequency of 4x4MHz=16MHz.
 
Top