Asked — Edited

Goto Last Loop Variable Goto + Variable Goto($Variable)

Has anyone figured out way to get the goto() function to work with variable so it can goto the last defined loop such as this :

 $lastLoop = ""

:loop1
$last = "loop1"

left(200, 0)
sleep(100)

print($last)

goto($last)   


this would allow to have the equivalent to calling a function and resuming the current loop after its execution. It would prevent me from using too many scripts and avoid lots of redundancies. My project currently has 50 scripts so I'm trying to find a way to shrink this number. :P


ARC Pro

Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

#17  

By the way, this is the proper way to post code snippets. Anyway your code would not cause a stack overflow anyway because it wouldn't even run due to typos...:P



inomeLimit
If (GetADC(adc2) >2.5 and GetADC(adc3) <2 and GetADC(adc1)<2)
Move(D2,"stop") 
...
goto(DomeLimit)

PRO
USA
#18  

Thanks to all for the answers. I am new to EZ-Script. Have only had my EZ-Bv4 for less than a week. But have my R2D2 already running around the garage.

#19  

@rz90208 Well then welcome... Nice Christening LOL... OK What? And you never posted a video or pictures? Shame on you... seriously we wanna' see...:) Is it an Astomech R2D2? There are a couple on here that rock....:)

PRO
Synthiam
#20  

Nice! that's awesome! I have an r2d2 collecting dust that i really need to get my act together on someday.

My career background is in tech security, as well as hardware in robotics. When building ez-robot from the ground up, i implemented a bunch of work-arounds for struggles that programmers have experienced. One of those, ironically to this topic, are stack overflows:)

The concept of EZ-Script and ARC is to run each control as a separate process. Think of these controls as totally separate programs. Each control can only run once, meaning it has only one thread. A single control will never have two threads to perform things twice, that would require to controls instead. The EZ-Script runtime works the same way, each instance can run only once.

Say you are using EZ-Script in the WiiMote control and the script is applied to a button. If the button script has a...


:loop
 #do something
goto(loop)

then the code will run for ever... until it's told to run again. In which case the script will be told to stop, and start again. This approach only applies to "Behind the scene" scripts, such as those in the camera control or wiimote, or myo, or etc etc etc...

The difference between the behind the scene scripts and a traditional EZ-Script control is just that. The EZ-Script control will only run once, and if it's told to run again while running, a message will be displayed in its console stating that the script is already running.

Take a look at the Examples folder that is included in ARC. There's a few Procedure example projects that demonstrate it.

#21  

@DJ sorry slightly off topic... I am curious about something and forgive my ignorance showing here. We all know arduinos are not multitasking controllers... sure they have interrupts... yada, yada, yada, but really they basically perform one instruction at a time... With ez robots approach where exactly does the mutli tasking/threading take place? In ARC or on the ezb4 itself? Or a combination of both? Again, sorry if this is an obvious answer...

PRO
Synthiam
#23  

Well - that's a complicated question! Now you've opened up a big can of whoop...

So here's the thing - an arduino, an ez-b, a PC, etc... are all not multitasking controllers. This is because CPU's are not multitasking. What is multitasking is software. If a CPU has more than one core, the multitasking of software utilizes the cores for "threads". Or, if there's only one core, the operating system uses interrupts with process priority and executes each "task" as a thread (i.e. a few instructions of each task at a time)

Threading programming has traditionally been a frightening place for inexperienced or over-confident programmers... and a scary place for security vulnerabilities as well. This is because even though software runs on top of hardware, there is no easy way to synchronize states.

There is another thread, started by the same poster as this thread which we hijacked, who is having issue with his camera. The issue is hardware related - or outside of ez-robot's control. The hardware can either be the network, a driver, a usb cable, etc... This is because even though software runs on hardware, it is dependent on the assumption that the hardware is performing 100% as expected. Hardware bugs is why software can suck, specifically in a threaded environment. Take for instance a driver loading in windows for a hardware device - the software can only assume everything is working as programmed.

Secondly, on the topic of the dangers of threading, is data synchronization. Meaning, when an operating system is running threads on multiple physical cores, how does each software thread know how to synchronize its state and when is the data in a specific memory address valid or not valid? Who's writing or reading to that memory? What core? What thread? What if two threads on different cores are attempting to read/write to the same memory? Who monitors it? What if the monitor is on a different core and thread? How do you trust the monitor...

So with this huge chunk of confusion - now i can introduce how ez-robot does things. First, we assume the operating system and runtime environment knows how the heck to handle threads, which .Net does very well (in it's own way, which we override with our own task scheduler). So ez-robot has our own task scheduler, and it is lighter weight than the microsoft one, and also specific to our needs. EZ-B.DLL and ARC.EXE both use the task scheduler.

Each control runs in a separate thread and uses the task scheduler to ensure only one of itself is executing at a time. This means multiple controls can run at once, but only one time per control - if that makes sense.

Here's something that you don't get to see. This is the debug output of the EZ Task Scheduler when loading the JD Example Project. See how many tasks are loaded...

Quote:

EZ Task Scheduler Initialized: v4 Video EZ Task Scheduler Initialized: Auto Position: fe0a73f6-d4da-4602-82ee-2c7e28cad869 EZ Task Scheduler Initialized: v4 Sound Progress EZ Task Scheduler Initialized: v4 Sound EZ Task Scheduler Initialized: Auto Position: 1c9387e7-11d2-4bfa-a656-43e27e717166 EZ Task Scheduler Initialized: v4 Sound Progress EZ Task Scheduler Initialized: v4 Sound EZ Task Scheduler Initialized: Auto Position: e018f951-b15a-4eb4-8d2f-93e1f621d191 EZ Task Scheduler Initialized: v4 Sound Progress EZ Task Scheduler Initialized: v4 Sound EZ Task Scheduler Initialized: Auto Position: e19a8c50-574d-479a-bb9d-90731b6358b3 EZ Task Scheduler Initialized: v4 Sound Progress EZ Task Scheduler Initialized: v4 Sound EZ Task Scheduler Initialized: Auto Position: 43b7610d-84df-49f1-807e-084b33b38304 EZ Task Scheduler Initialized: v4 Sound Progress EZ Task Scheduler Initialized: v4 Sound EZ Task Scheduler Initialized: Init EZ Task Scheduler Initialized: e87b5001-9d76-47d5-83e2-94226cc80dbe EZ Task Scheduler Initialized: 15610d79-6037-4f0e-b8be-d0f5af6c4cf2 EZ Task Scheduler Initialized: f1060ce3-885b-4de5-acc1-ecb90dd191c9 EZ Task Scheduler Initialized: 1788a0ab-b550-4210-9671-a4a992c093b1 EZ Task Scheduler Initialized: 5743ed5f-82f7-45f9-91d5-c85e74487c19 EZ Task Scheduler Initialized: ec07164c-ab5f-4bf3-afe2-1f8ac8697696 EZ Task Scheduler Initialized: c0b44a47-d076-47d1-a894-8e50a5c7975d EZ Task Scheduler Initialized: 01b32271-8cab-49c1-a284-0f172c0d4808 EZ Task Scheduler Initialized: 398794c5-a1b9-4a97-93f3-9bbb5c5133ad EZ Task Scheduler Initialized: e1a9bfd8-5688-4034-b782-de470bd18ebe EZ Task Scheduler Initialized: 391b195c-8142-4d17-94a0-86d1ee69770a EZ Task Scheduler Initialized: b2f1742d-8ed5-4b19-bda6-0e8ecc000f41 EZ Task Scheduler Initialized: eb4fe56c-9d33-4ae9-9580-a6fbfbb66338 EZ Task Scheduler Initialized: 809baa1b-0438-4cb0-b767-098e8d4b3135 EZ Task Scheduler Initialized: 3c38fd06-fc2d-4f07-968c-ee73678c9510 EZ Task Scheduler Initialized: 72add477-3ebd-4394-bf7a-6ddc0843e3cd EZ Task Scheduler Initialized: 31e94017-eb1a-4755-bb32-49c05fcf1ece EZ Task Scheduler Initialized: 8adcf783-8439-43bf-9485-1a9593f1d7dd EZ Task Scheduler Initialized: 8debbbe3-6d6c-4cf9-8250-e091312eff78 EZ Task Scheduler Initialized: 01dbec08-c55e-4eff-a68d-e242e5130f87 EZ Task Scheduler Initialized: 99319c0e-a46a-4fbf-bd83-75bfe70c0885 EZ Task Scheduler Initialized: 3b026b66-87d3-486e-889a-36b7b1120910 EZ Task Scheduler Initialized: 7ef28e69-0e6f-4ef7-9d59-e1303e37b911 EZ Task Scheduler Initialized: c8fd4f42-5e25-48aa-8078-4dfe704ee509 EZ Task Scheduler Initialized: 33ec792c-e7eb-4e9a-a195-cc5261270b00 EZ Task Scheduler Initialized: dc6d0a90-1f37-4132-a0c1-31775aa111fb EZ Task Scheduler Initialized: e37936ae-3b0e-427d-9f8f-c80d77e9549e EZ Task Scheduler Initialized: 7aa2621e-4921-4edb-86fa-1f43d095d2b4 EZ Task Scheduler Initialized: f13e410e-7446-4419-ae08-c2672dbdf2ee EZ Task Scheduler Initialized: bdfd33b4-65fb-4134-9898-565b6115840c EZ Task Scheduler Initialized: 90ae8655-ec7e-417f-8972-a27966b8099d EZ Task Scheduler Initialized: 245ea96a-8c43-46c8-98a5-31eaf2a21440 EZ Task Scheduler Initialized: 33a5f358-3d8d-436e-9306-eac2d1330d11

Because they're all talking TO and FROM the EZ-B, now we get into the communication side of things...

The communication protocol of the EZ-B is buffered synchronous - meaning commands are sent and received FIFO in a linear fashion. All the kids line up when the bell rings to enter the school.

The buffered side of the synchronous introduces threading. To reference the multi cpu core bit above, the ez-b communication protocol synchronizes the EZ-B to the PC's EZ-B.DLL communication channel, which in-turn connects to the appropriate EZ Task.

So the communication channel is not "threaded" because it is buffered synchronous FIFO - however, once the data is in the EZ-B, it's handled in threads again.

The EZ-B has 2 microcontrollers, and 1 for the camera, and other peripherals have their own as well. So let's just reference the EZ-B micros to start...

The first micro on the EZ-B that "talks" to the PC and buffers the FIFO is Wifi module. All versions of the EZ-B Comm Board use a real-time multitasking operating system (RTOS). The latest EZ-B (v4.x/2) has a very advanced custom RTOS, made specifically for EZ-Robot. The RTOS has a bunch of threads that are separate processes. You can telnet into port 8080 of the v4.x/2 and view the tasks that are currently running.

You will see a bunch of processes...

User-inserted image

Each process is a thread on the CPU. The processes are little "programs" that perform a function and share data with mutex locks, etc.. You can see how there's processes for the HTTP Server, CLI Server, Clients, Network Broadcasts, etc... These are all separate threads making sure the communication between the EZ-B and the PC works and is buffered. This is why the v4.x/2 is so friggin awesome and reliable - using dma with software/hardware buffers and monitors and mutex locks and a pile of other stuff. It's 380k of compiled opcode that makes the next gen ez-b an entirely new beast.

Now, we're talking about the top CPU on the EZ-B. There is another CPU on the EZ-B which is on the bottom board. And that chips is actually the EZ-B. It's got a lot of code on it, which does a lot of things. It runs very specific code that "listens" for commands - while it bit-bangs ports and buffers data in it's hardware dma. The OS on this chip is not "multitasking" at all - however, it does a bunch of things at the same time using hardware timers and DMA. It understands things like the Audio CODEC and servos and pwm, etc.. all in software. Because while micro's traditionally are limited to the number of PWM hardware peripherals for servos, i have very efficient code that i wrote 4 years ago which bitbangs PWM and ramping on 24 ports, dynamically.

To answer your question in a summary...

  1. OS is threaded
  2. ARC is not threaded
  3. ARC controls are threaded
  4. EZ-B.DLL functions (rgb animator, auto positioner, audio player, video, etc) are threaded
  5. EZ-B.DLL Comm channel is buffered synchronous FIFO
  6. EZ-B v4 Comm CPU is threaded RTOS
  7. EZ-B v4 Main CPU is not threaded but performs many functions at once using hardware timers and dma

I guess the short answer is that the "threading" or "processes" are distributed across a variety of physical hardware - including both the EZ-B and various software on the PC.

#24  

First off to the OP...again apologies for the thread hijack...again... @DJ... Very nice and detailed explanation, I got chills LOL :)... I understood about 95% of what you wrote. One has to really appreciate the amount of work you put into not only to develop the ezb and ARC but the continued updates you have been giving us... I am really looking forward to using the upcoming ezb4.1/2 in my projects....