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

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

#1  

Looks like another math problem for Rich;)

#3  

@Mel... Justin who? Are you talking about JustinRatliff? yeah, he don't like math Mel... Unless you were trying to be funny.... I don't like math either.... I do it when I have, however....

#4  

To duplicate that arduino command I think the first question is this. Is their an ez - script command to determine how many elements is in a array.

United Kingdom
#5  

To tackle the "what does the getping represent", it's raw data from the ping sensor, with 255 being it's furthest away and 0 being closest. The resolution of the sensor will determine how far each unit represents. The ping sensor in the EZ-Robot kit has a 255" range which makes it easy, 1 = 1" however if it was a different one and a value of 100 was given at 1M away this would be as easy as working out the ratio. 1000mm / 100 units = 10mm per unit.

As for the array, I'd have to check the script manual etc. since I've not used arrays yet. I'd also have to read the OP properly to find out what is actually trying to be accomplished. I always find it easier to start from a blank slate than to try porting over complex Arduino code, often it's much simpler in EZ-Script than Arduino so porting can overcomplicate matters.

#6  

I've been reading the EZ script manual heavily and it does not have many of the function (like math) you might find in an arduino....my suspicion is that many of those math functions are not needed.

In the example code shown the array is used to move a servo in a pan motion. You could use RADAR for that or you could use an Auto Position control and store the movements in a sequence then call up the sequence via a script. The arduino you need the heavy math to do something simple....in EZ-Robot you don't need the math...you just need to point, click and configure (for most things).

That is assuming you wanted to pan a servo like a turret?

I'm starting to believe, to get things to move or take sensor readings, you don't need a lot of match with EZ-Robot. Basic math, greater then, less then, +, -, =, is probably the most common math functions 99% of us would use. (feel free to point I'm wrong on that).

For the A.I. math and the 1%ers out there...I'm leaning towards an open source 3rd party app like EZ-Face to perform those math functions and return results to ARC. Any thoughts on that?

United Kingdom
#7  

What math commands do you think are needed but not available?

#8  

I am not sure that the math is really the question here though it may play a role in the grand scheme of things.

If we put aside the math aspect of this the basic question I need answered is this.

How would I iterate through the elements of an array, get the contents of each element, store the contents in a variable and do it in a way that I don't have to rewrite code the same code throughout my app?

This array would be used multiple times.

Thanks for all the help.

United Kingdom
#9  

If a simple command doesn't exist for a process you need to repeat time and time again what I do is write it as a new script and call that with a ControlCommand() whenever I need to use it.

For an example, my latest PingRoam scripts use this method. Where it checks for the ping reading, because GetPing() wasn't all I needed it to do, I wrote a script called "Get Ping" which has the required commands in it. Then the main script uses ControlCommand("Script Manager", ScriptStartWait, "Get Ping") to start the repeated code, the main script will wait until the Get Ping script is finished and then moves on.

Where the code is slightly different you can incorporate variables. For instance, if there were 2 ultrasonic sensors but the Get Ping method was the same for both you could have the GetPing() command use variables for the ports and set the ports before the ControlCommand. i.e.


$pingtrigger = "D0"
$pingecho = "D1"
ControlCommand("Script Manager", ScriptStartWait, "Get Ping")

And then the Get Ping script


$ping = GetPing($pingtrigger, $pingecho)

#10  

@Darathian I think to really answer the question, we need to take a step even farther back. Rather than thinking about the array for now, what is it that you are trying to get the robot to do?

With that answer, we can better determine if array processing is even what you really need and either make suggestions for achieving the result, or better answer the question of how to access the data. (assuming data processing of some kind, array or other, will be needed for your function, the other question we'll be asking is where is that data coming from. Is it fixed or variable. Coded into the app or delivered from an external source like a sensor?).

Alan

#11  

The reason I went down the porting route is that the existing code I already have for the arduino worked really well especially when dealing with being stuck in a corner.

Here is what I will do. I will provide the logic that I want to recreate in ez-script.

#12  

I appreciate all the help.

@Rich

What your describing using the control commands is like the procedural examples if I am not mistaken and makes sense to me. I will look further into that.

@thetechguru

Here is the basic logic.

Iterating through an array seemed to me at least to make multiple aspects of doing this much easier with less code.

Basic Background

A) Base with two servos and wheels. B) Ping sensor on a servo.

The basic logic for the main program is this:

  1. Move forward.

  2. Advance the ping servo to next position and wait for the servo to get into that position prior to doing a ping.

  3. Do a ping and ideally get the distance in cm or inches.

  4. If object/obstacle detected in +/- 36 degrees from center is within a "too close" threshold stop and run "find opening" code (I will provide the find opening code logic further down in the post) which result references a certain position of the servo when an opening is found.

  5. Convert that position to a degree value.

  6. Convert the degree angle to the amount of time it will take for the robot to turn and face the direction (Opening)

  7. Turn robot to face that opening

  8. Move forward and do steps 2-7 again.

At a high level the find opening code:

a)Rotate turret until an opening becomes visible. If it reaches servo limit, turn back to first angle of detection and try scanning toward other servo limit.

b) If still no opening, rotate robot 90 degrees and try again.

United Kingdom
#13  

Have a look at this topic and this project

It sounds like you are describing something that closely resembles the PingRoam scripts I wrote/am writing. The project and scripts are modular, commented and easy to adjust, it may be of some use to you.

#14  

@Rich always beats me to the answers, but since I was going to point you to his project, no harm:)

This does sound very much like what ping roam does. Should be fairly simple to adapt to your needs.

Alan

#15  

@Rich

I am busy going through your scripts as well as the topics you listed.

The array of values 0 2 4 6 8 10 9 7 5 3 1 from what I can tell is mainly used to:

  1. Advance the ping sensor to the next position.
  2. Keep track of the position of the ping sensor servo
  3. The ping sensor position is converted to a degree angle that is then used to rotate the robot to face the ping sensor position when an opening is found.

I may be able to use the following to do the same thing for item 2.

GetServo( Port ) Returns the servo Position value of the specified port Servo position is between 0 and 100 Example: $x = GetServo(d0)

Thanks

#16  

Just to clarify, if you are using a V4 then getServo will report back positions from 0 to 180.... 0 to 100 was used with the V3....

#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)