Shop OBEX P1 Docs P2 Docs Learn Events
Object confusion — Parallax Forums

Object confusion

WhelzornWhelzorn Posts: 256
edited 2007-11-04 14:38 in Propeller 1
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.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-03 05:29
    You'll need to post your code as attachments to a message or at least a diagram showing who calls what and what objects are declared in who.
  • deSilvadeSilva Posts: 2,967
    edited 2007-11-03 08:42
    @Justin: You fell into a well known trap: Instantiation of objects.
    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 smile.gif
    http://forums.parallax.com/showthread.php?p=680258

    Post Edited (deSilva) : 11/3/2007 2:51:31 PM GMT
  • WhelzornWhelzorn Posts: 256
    edited 2007-11-03 14:46
    aah thank you deSilva, that's exactly my problem. I was just unsure what to call this problem because I've never run into it before
    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!
  • hippyhippy Posts: 1,981
    edited 2007-11-03 15:59
    @ Whelzorn : When deSilva says Objects are NOT "modules" that's key to the problem, and I ran into it also.

    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.
  • WhelzornWhelzorn Posts: 256
    edited 2007-11-03 16:19
    Yeah, in this case it's the FullDuplexSerialExtended, and I don't really know where to start...
    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.
  • hippyhippy Posts: 1,981
    edited 2007-11-03 16:37
    For serial, I got pointed to "SerialMirror" on the object exchange ( page 3 or 'interfaces' AFAIR ) which was very useful for understanding a 'shared, single object'.

    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.
  • WhelzornWhelzorn Posts: 256
    edited 2007-11-03 16:58
    Oh thank god. The SerialMirror object works Perfectly! It'd be nice not to have to include a whole seperate object for a single-object use serial and a multi-object use serial, but whatever. Until I finish the rest of the project, I won't worry about optimizing my code, I'm just happy it works.
    Thanks!
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-11-03 17:26
    I'm sure there are exceptions, but here's a general rule:

    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
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-11-03 17:44
    BTW: Whelzorn, I like your cat picture. Looks like it just came out of a volcano! smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • WhelzornWhelzorn Posts: 256
    edited 2007-11-03 17:57
    ha ha thanks, I found that pic somewhere on the interweb about 3-4 years ago when I started posting here.
    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.
  • rjo_rjo_ Posts: 1,825
    edited 2007-11-04 02:18
    Whelzorn,

    Fess up, you loved your cat so much you had him stuffed... what kind of LEDs are you using?

    Rich
  • WhelzornWhelzorn Posts: 256
    edited 2007-11-04 14:38
    Rich,
    I used about 20 Luxeon V's for my fluffy. Driving all those was a hell of a challenge, let me tell you.
Sign In or Register to comment.