
Darathian

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.
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
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.
And then the Get Ping script
@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
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.
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:
Move forward.
Advance the ping servo to next position and wait for the servo to get into that position prior to doing a ping.
Do a ping and ideally get the distance in cm or inches.
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.
Convert that position to a degree value.
Convert the degree angle to the amount of time it will take for the robot to turn and face the direction (Opening)
Turn robot to face that opening
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.
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.
@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
@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:
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
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....