array to store data

Hello.
Am bit week in programming. Could anyone please give a sample code to create an array where i can store data of the positions returned from my servo.
The data which is stored in array must be used by the picaxe to control the servos when the specific command is given. Am using a picaxe 28x2 for contolling the servos in the legs. picaxe 18m2 is used for the hands. A bluetooth module is connected to 28x2 for contolling the humanoid and the 28x2 send data to 18m2 for the working of the hands.
I have hacked my servos to return position values and it works.
I want to use this data to make my humanoid robot to walk properly.
I have used 6 servos for its leg (3 each) and 8 servos for the hands(4 each). After reading some posts in the forum i have found out that the EEPROM or scratchpad memory can be used for this purpose, but am stuck with the coding part.
I just require some sort of a sample code or some guidance in this matter.

Thank you.
 
Last edited:

lbenson

Senior Member
How big an array are you talking about? 28X2 has ram available above the named variables B0-B55, addresses 56-255 accessible with peek/poke and bptr. For instance, to display all those byte values:

for bptr = 56 to 255 : sertxd(#bptr,"=",@bptr, cr,lf) : next bptr

There are also bytes 0-1023 of scratchpad, accessible with get/put and ptr.

for ptr = 0 to 1023 : sertxd(#ptr,"=",@ptr, cr,lf) : next ptr

This is equivalent:

for w26= 0 to 1023 : get w26, b54 : sertxd(#w26,"=",#b54, cr,lf) : next w26
 

hippy

Ex-Staff (retired)
You can use RAM as an array, accessed by using POKE and PEEK commands, and via @bptr, @bptrInc and @bptrDec variables. You can also use scratchpad memory accessed by using PUT and GET commands, and via @ptr, @ptrInc and @ptrDec variables.

Scratchpad is easier to use as RAM space is shared by variables so you have to be careful where you put things.

Code:
b0 = 100
For b1 = 0 To 5
  Put b1, b0 ; [PLAIN]Scratchpad[b1] := b0[/PLAIN]
  b0 = b0 + 1
Next

For b1 = 0 To 5
  Get b1, b0 ; [PLAIN]b0 := Scratchpad[b1][/PLAIN]
  SerTxd( "Scratchpad[", #b1, "] = ", #b0, CR, LF )
Next
 
The array must store nearly 50-100 bytes. Each servo position must be read and stored.
Thank you for the reply. Could you please say how to save the data into an array received from the ADC.
 

hippy

Ex-Staff (retired)
Perhaps something like ...

Code:
For b1 = 0 To 5
  ReadAdc ADC_PIN, b0
  Put b1, b0 ; Scratchpad[b1] := b0
Next
 

lbenson

Senior Member
If each of your 6 leg servos and 8 hand servos requires 100 bytes, then you don't have enough space in the 1024-byte scratchpad for your data. If you could limit it to 70 bytes each, then you could fit single-byte ADC readings for 14 servos into 980 bytes like this.
Code:
#picaxe 28x2

# b0-b3 reserved for bit values if needed
symbol servoNumber = b4 ' 14 servos: value of 0-13
symbol adcCount    = b5 ' up to 70 adc reads
symbol ADC_PIN     = b6 

main:
  do
    for adcCount = 0 to 69
      for servoNumber = 0 to 14 for each servo
        ptr = servoNumber * 70 + adcCount      ' where to store next reading for this servo
                                               ' you must define ADC_PIN; 28x2 has 0-4, 8-14, 16-19
'        lookup servoNumber (0,1,2,3,4,8,9,10,11,12,13,14,16,17,18,19),ADC_PIN
        lookup servoNumber (A.0,A.1,A.2,A.3,C.3,B.2,B.3,B.1,B.4,B.0,B.5,C.2,C.4,C.5,C.6,C.7),ADC_PIN
        ReadAdc ADC_PIN, @ptr                  
      next servoNumber 
    next adcCount 
  loop
This takes 70 readings for each servo. Servo# 0 uses positions 0-69 in the scratchpad; servo# 1 uses 70-139, etc. I'm sure it's not how you would to about filling the arrays with data, but it might give you ideas.

Note that I'm not sure which of the two "lookup" commands should be used. The command example in the manual takes a PIN.# (as in the uncommented lookup), but I seem to recall that if you use a variable, you need the ADC channel number, in which case the commented lookup command would be used.
 

lbenson

Senior Member
Note that if you are wishing to make "canned" steps of motions which you can play back, you will want to store these to external eeprom rather than put them into ram, where they would disappear when the chip is power cycled.

If you could more fully explain what you want to do, people could provide more assistance.
 
Top