Is there a way to make a variable global to the child?
lardom
Posts: 1,659
I changed a value of a variable from 1 to 0 in a loop in the parent object. I passed the address of that variable to the child and created another loop to monitor that variable and watched the result with an LED. The child object could see the initial value but would not respond to changes that were made in the parent unless I used the "@" symbol again. I was looking for a way to let the child know when the parent had finished executing. Is there a way to do this?
Comments
I wrote an object where the Ping acts as a motion sensor. The problem is that a breeze can also trigger a scan. I want a method as reliable as monitoring wheel encoders. I'm using steppers. I want the motors to write values to a "universal" global address that could be seen by the 'servo/Ping child.
I'm stuck on how to update object "two".
What's the reason for having the servo / PING handling in a separate cog (from the main one)? Is the servo and PING functioning autonomously? What about accounting for the motion of the robot? How's that done? If you're stopping the robot to avoid motion artifact, why not do the scan in the main cog? If you want the servo and PING to function autonomously, you do indeed want to have motion information passed on to the servo / PING cog via shared variables.
It works but it's unreliable. I hope that makes sense.
In a nutshell; When the motors finish executing I want them to copy "1" to a universal global address which the Ping object can see.
Who sets the flag values to zero?
When you call the start method for the motor, you pass it the address of that motor's flag long. The start routine saves the address in a global variable (VAR) for the object. When the start routine does its cognew, it doesn't have to do anything special because the new cog's code can directly access the global variable that holds the flag's address. I don't recommend passing the address to a separate method because the address should be known before you start up the new cog.
This works for me:
It is a big deal when people take the time to clarify concepts by writing code for me. Understanding a concept is better than simply memorizing syntax. Thank you.