Streaming function. Multiple functions.

Typically: "How do I... ", "How can I... " questions
Post Reply
ArthurS
Posts: 28
Joined: 25 Jul 2021, 20:00

Streaming function. Multiple functions.

Post by ArthurS »

This is a multi-threaded script (part of the coroutine Main ())
I need to loop my workflow. But the next step should only be performed when the isnextTest variable becomes true. I try to read at every step of the StringSignal loop, which contains an array with an array of bool type representing the readiness of the drones, and if all the values ​​of the array == true, then the operations in the loop can start again. But this check for some reason goes beyond the time frame and everything crashes.



I will give a part of the code where I am trying to do this:

Code: Select all

function coroutineMain()
-- my initialization...
 	while true do
            	local testssolved=0
            if testssolved>0 and  waitingforNextTest() then
           	if Testcount>0  then
         	
         	--my functions are executed, which needs to be looped
        	
        	 sim.switchThread()
         	else
         	print("END!!!!!!!!!!!!")
           	end
          end
    	end
end


--somewhere below one of my functions...

function waitingforNextTest()

    for i=1,#quadcopters,1 do
            local copterscript=sim.getScriptAssociatedWithObject(quadcopters[i])
            local 	isAtstartpoint=sim.callScriptFunction("isAtstartpoint@"..sim.getScriptName(copterscript),copterscript,isAtstartpoint)
            if isAtstartpoint==false then
            return false
            end
    end
return true

end





maybe I'm doing something wrong. Or do I need a separate multi-threaded function where I can check safely? Help me please!!
If possible please insert a short pseudocode into my patch code.

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Streaming function. Multiple functions.

Post by coppelia »

Hello,

please post some minimalistic scene that illustrates your problem. I am not sure I understand what exactly you are trying to achieve.

Cheers

ArthurS
Posts: 28
Joined: 25 Jul 2021, 20:00

Re: Streaming function. Multiple functions.

Post by ArthurS »

Hello. I am sending you the main scene and 3 models that are used there.
I will provide access to the folder on the google drive. https://drive.google.com/drive/folders/ ... sp=sharing
You should scale this folder to the path "C:\Program Files\CoppeliaRobotics\CoppeliaSimEdu\projects" (or otherwise change some of the loading paths in the MAIN file).
Start MAIN. It contains that problematic part of the program.
script "Scripts" contains everything you need.

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Streaming function. Multiple functions.

Post by coppelia »

Sorry, this is not what I mean when I say minimalistic scene: we don't have the time to read all your code and try to figure out what you intended to do. Instead, put a little bit of effort into at least trying to simplify your scene or problem to a minimum, in order to facilitate us to help you. Did you at least try the few code snippets we posted to your other question? it seems not, you didn't even bother commenting or giving a thank you.

Cheers

ArthurS
Posts: 28
Joined: 25 Jul 2021, 20:00

Re: Streaming function. Multiple functions.

Post by ArthurS »

Hello, sorry, I did not understand you correctly, and in order to show all the details of what is happening, I threw off the entire code. I simplified the scene and rewrote everything in a simple way in a couple of lines. Now this is one scene file.
https://drive.google.com/drive/folders/ ... sp=sharing


Here is the main loop, which at first does the functions I need and then should stall for another 1 cycle and until the condition of the checking function is fulfilled.
In this case, this is the function(I loaded her a little for an example): f()
Everything works as it should in this simulation. the cycle does not loop again and hangs on false false .....
But if you replace this function f () with my function (it is all commented out and is in the code below, then everything breaks down - or rather, after a few seconds of its operation, a yellow "abort execution" window appears). Why is it with this function that the threads do not have time to change?
I also noticed that insert a simple function f () into my previous code, then everything also breaks, it may not be in the functions and interaction of my drones and everything else at all. That's why I threw the whole project.
I don’t understand what the problem might be. I really hope for your help!!!

And now about the last post. I have not had time to look and analyze yet. Do not be discouraged, please !!! I work on problems gradually)

Post Reply