Asked — Edited
Resolved Resolved by Rich!

Sizeof Array

Does anyone know if its possible and how to recreate the Sizeof command from Arduino processing in EZ-Script.

I am trying to port some code to EZ-Script but not quite sure how to accomplish this.

Arduino Sizeof command

Here is what I am really trying to port:

Lets say you have a array of values:

int sequence[] = {0, 2, 4, 6, 8, 10, 9, 7, 5, 3, 1};

You calculate how many degrees each value represents. (Each value in the array means a certain number of degrees or servo position.

// Pre-calculate degrees per adjustment of turret servo. const int degreesTurret = 180/(sizeof(sequence)/sizeof(int)-1);

You use this value to move the servo that many degrees

theta = sequence[i] * degreesTurret;

Note: i gets incremented using i++;

Also what does the value from getping represent. Is that a raw value from the sensor or does that value have another meaning like distance in cm and inches.

Thanks


ARC Pro

Upgrade to ARC Pro

ARC Pro will give you immediate updates and new features needed to unleash your robot's potential!

#17  

@Richard R

I copied and pasted those lines from the script help file. Seems like there might be something to update by the EZ- Robot team unless I missed an update that fixes that entry.:)

I am using a v4.

Thanks

#18  

Since the script by rich closely matches what i am trying to do i am going work through Rich's script and adjust it based on my needs.

I still have this nagging voice in the back of my head that wants to know how to iterate through an array but I will play around with it a bit and mostly ignore the voice for now:)

Thanks all

#19  

If you do wind up needing functionality not in ARC, there are a few options. The SDK can be used either standalone to completely replace ARC, but then you need to write everything in dotnet (either vb or c#, but more examples in c#) or to pass variables in and out of ARC, meaning virtually anything you can write in dotnet can be done with ARC.

If you don't know dotnet, there are a couple of good coders who participate here who often offer to help (in fact, that is what Justin was talking about a few posts up).

There are some other ways to pass data in and out without knowing dotnet (telnet, web, file i/o, rss) that can be used to integrate into external apps.

Finally, if you articulate a need that can't be done another way, DJ usually adds iit within a few releases. In fact, some capabilities that started as SDK projects have been built in as features because the need was obvious (like face recognition).

Alan

#20  

@thetechguru

I have been slowly familiarizing myself and I am aware of quite a few of the options. I do appreciate you pointing them out though.

I am somewhat familiar with c# and have used the sdk. It's EZ-Script I am trying to get a handle on since I am used to c#.

In this project I was trying to stay away from having two apps having to talk to each other so wanted to use EZ-Script by itself.

Some specific items regarding the arrays that struck me was this.

  1. The script help refers to a fillarray command but when I try to type it into a script control it's not an option.

  2. I was somewhat surprised not to see a do loop in ez-script.

Thanks

#21  

Quote:

1. The script help refers to a fillarray command but when I try to type it into a script control it's not an option.

  1. I was somewhat surprised not to see a do loop in ez-script.

Hmmm.. I don't have a clue how to use it, but when I start typing "fill" into a script it pops up with FillArray( variable, default value).

I believe Repeat, RepeatUntil, and RepeatWhile commands work like do loop (but I am not a script expert, so take with a hefty grain of salt).

Alan

#22  

Odd perhaps I will try to reinstall my copy of ARC.

I am looking at the other loops to accomplish the same thing.

Thanks

#23  

I played around a bit and iterating through the array seems to work this way as long as you know the array size.


# Define the array size and contents
$arraySize = 11
DefineArray($X, $arraySize)
$X[0] = 0
$X[1] = 2
$X[2] = 4
$X[3] = 6
$X[4] = 8
$X[5] = 10
$X[6] = 9
$X[7] = 7
$X[8] = 5
$X[9] = 3
$X[10] = 1


#Iterate over the array and return the values

$index = 0
RepeatUntil ($index = $arraySize)
   $arrayContents = $X[$index]
   print("The contents of $X[" + $index +"] is " + $arrayContents )
   $index++
   sleep(1000)
EndRepeatUntil


I am still trying to get a handle on getting the number of elements in the array (array size)