Object confusion
Whelzorn
Posts: 256
Ok, so I have a main object, a Radio object, and a sensor object.
You call sensor.gather from the main object, the sensor object talks to the sensor hardware via serial. When you call for the sensor to return data (sensor.gather), it uses a loop and returns a byte every iteration. It (the loop) runs for about 150 iterations.
Each iteration, it needs to send that byte out the radio with Radio.tx. The radio needs to be started with radio.start. This is done at the beginning the main object.
Now the problem is, for some reason you can't call radio.start (which simply does a serial.start on the pins the radio is attached to) from a different object than you call radio.tx. It works fine when you call them from the same object though.
I can't just return the data from sensor.gather to the main function and then call radio.tx from main, because each byte needs to be sent at the end of each iteration of the loop. So either I need to make a new routine in main and call it from the sensor.gather routine after each iteration (which it won't let me do, it says I can't call main from another object) or I have to call both radio.start and radio.tx from the sensor object (which I can't do because I need to use radio.tx in the main object as well).
Is there any way I can do this?? it's driving me crazy.
Thanks,
Justin
Oh and if this is impossible to understand, I'll try and find another way to explain it.
You call sensor.gather from the main object, the sensor object talks to the sensor hardware via serial. When you call for the sensor to return data (sensor.gather), it uses a loop and returns a byte every iteration. It (the loop) runs for about 150 iterations.
Each iteration, it needs to send that byte out the radio with Radio.tx. The radio needs to be started with radio.start. This is done at the beginning the main object.
Now the problem is, for some reason you can't call radio.start (which simply does a serial.start on the pins the radio is attached to) from a different object than you call radio.tx. It works fine when you call them from the same object though.
I can't just return the data from sensor.gather to the main function and then call radio.tx from main, because each byte needs to be sent at the end of each iteration of the loop. So either I need to make a new routine in main and call it from the sensor.gather routine after each iteration (which it won't let me do, it says I can't call main from another object) or I have to call both radio.start and radio.tx from the sensor object (which I can't do because I need to use radio.tx in the main object as well).
Is there any way I can do this?? it's driving me crazy.
Thanks,
Justin
Oh and if this is impossible to understand, I'll try and find another way to explain it.
Comments
Objects are NOT "modules" as you know.
You have two different instantiations and it depends on the set of VARs whether it works out (by chance!) or not.
Look through the dozens of threads explaining the thing, offering advice and work arounds.
There is a Q&A in the stickies, where MYNET explains this for FLOAT32 in depth - I shall look for it soon...
Edit: There it is.. Reference will be needed once a week, I think
http://forums.parallax.com/showthread.php?p=680258
Post Edited (deSilva) : 11/3/2007 2:51:31 PM GMT
Mike: yeah, the code's a lot more complicated than what I have explained so I was dreading having to post it. Next time I'll do a diagram though.
thanks!
Objects cannot call up to parents nor across to other objects defined by their parents, but a single sub-object can be included and referenced by the object, its parent, and any other object in your system. The requirement is that such an object must be designed to be used that way or you end up with multiple instances of the same object and interacting with one has no effect on the other instances.
Sometimes that's easy to achieve, sometimes hard, and some cases impossible without a complete redesign, and even then may still be impossible in the way you would like it. Nested objects, particularly those designed as abstraction layers for other sub-objects, create the worst problems I find.
I need to create 2 serial ports with the object^, one only needs to be used within the sensor object, but the other needs to be used all over the place.
I have a similar problem to yourself. As long as the object which defines the two sub-objects is only included once you will be okay, include the "shared, single object" wherever it is needed elsewhere, the other only in that object. If you need to include the parent/wrapper object itself multiple times, that's when it can get real messy.
If both serial port objects are created as "shared, single objects" they can be included anywhere ( and as part of any larger object ) with very little overhead and as long as the one which should only be used through one 'path through the objects' is only used that way, everything should be okay. It takes a bit of getting ones head round, and I'll admit I'm not quite there yet in my own design.
Thanks!
If you want different independent instances of your object in your program, keep your SPIN (HUB) variables in the VAR section. If you want one instance of your object to be shared throughout your program, put your SPIN (HUB) variables in the DAT section. This is because every time you call out (instantiate) your object in an OBJ section, it uses the same copy of everything in memory except the VAR section. The compiler creates a new VAR section for each object instantiation.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Post Edited (Ken Peterson) : 11/3/2007 5:42:09 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Anyway, I'm glad I got stuck on this little problem, it's taught me a lot about the way this whole Spin object thing works.
Fess up, you loved your cat so much you had him stuffed... what kind of LEDs are you using?
Rich
I used about 20 Luxeon V's for my fluffy. Driving all those was a hell of a challenge, let me tell you.