Asked
Is there a standard solution in ARC to slowly move the robot servos to an initial position when the ARC program starts?
Especially with larger robots, switching on puts a lot of dynamic load on the servos and puts a strain on the entire mechanics of the robot.
If there is no standard solution available, how could integrate a Python or a Java script to do this job?
Related Hardware EZ-B v4
Dave I would be interested if you didn’t ask Athens not to use else if statements if she would have exposed the function command and the random numbers mapped to objects lookup table. I suspect she would have just created a long list of else if statements like the following.
The question would have to include the fact there were goto statements that he was looking for a JavaScript equilevant. So you could say
@athena, Dave uses ezscript in ARC and wants to convert to JavaScript. His concern is he doesn’t know how to replicate goto statements from ezscript to JavaScript. Essentially the goto is like a gosub in basic, where it acts like a subroutine and returns. Show Dave how to have many functions based on various states of a variable in an if condition in JavaScript. Also show how to do the same with a switch statement.
nink, remember that Dave already is using a long IF/ELSE statement. So the solution would include with another IF condition or SWITCH.
Certainly! In JavaScript, the concept of
goto
statements doesn't exist as it does in some other programming languages like BASIC. Instead, JavaScript uses functions to encapsulate code that can be called from various places, which is similar to thegosub
routine in BASIC. Functions allow you to jump to a block of code and return to where you called it from once the function's tasks are completed.Here's how you can use functions and
if
statements to handle different states based on a variable's value:Alternatively, you can use a
switch
statement, which can be more readable when you have multiple discrete states:In both examples, you define a function for each state, and then you use either an
if
statement or aswitch
statement to call the appropriate function based on the value ofcurrentState
. This approach eliminates the need forgoto
by structuring your code into callable functions that act as subroutines.I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
Ya that’s far more readable! And exactly what Dave is asking, I believe.
I think that is pretty close it just didn't capture the random aspect Dave wanted just the line
would need to say some thing like the following
And using my messed up method I still think you could just name the functions state1 instead of stateOne and then just call the function with the Random Number at the end so you don't check state you just call state. No else if or switch table required
So replace all the else if lines with
Ah, i missed the part about random. So there's already a random function in arc. As you start typing in ARC script editor, it shows available commands. That's called "intellisense". You can turn it on or off. In Javascript or python, you can categorize functions. So all servo stuff is in Servo. and all Digital stuff in in Digital.
Well, the random is documented here..
so you'd do this..
or even more collapsed. You can remove the variable and switch directly on the return of Utility.getRandom()...
Interesting I pasted the code in ARC and with the getRandom you have to do Max + 1 as the answer is never Max only Max-1 Edit OH I didn't RTFM it it says max EXCLUSIVE Random integer between min (inclusive) and max (exclusive).
You guys are amazing. Thanks for taking my problem and running with it. There is a lot to digest here. I think with this help you've provided I can get started converting these few completed scripts I have. I'm not able to get deep into this till later tonight or tomorrow. I have some important family and home things to attend to.
I like the suggestion @DJ made that I should post that script in a different thread and ask for @Athena to help convert it. If I ask in the right way maybe she can help me convert, clean up and condense.
Again, thanks for the wonderful tips and examples.
More to follow.