Shop OBEX P1 Docs P2 Docs Learn Events
Why use more than 1 Object? — Parallax Forums

Why use more than 1 Object?

cnelson700cnelson700 Posts: 31
edited 2010-06-13 20:30 in Propeller 1
Seems to be a very simple question.· Is the answer simple?

If I want a machine to have·7 independent processes (7 cogs running their own progs)
*that communicate and coordinate with each other by reading/writing the same variables,
*and the variables in the VAR section of my object are global to all cogs that the object is running in,

then why would I want to break up my prog into multiple objects instead of multiple methods in the same object?

Autonomous Tank example
cog0 - Lead commander
Cog1 - object detection
Cog2 - steering
Cog3 - drive (fwd, rev, stop)
Cog4 - aim/fire
Cog6 - high speed A/D conversions (pasm)
Cog7 - GPS

Lead commander checks system status and waits for 'all systems ready'
while
steering and aim calibrate their positions then write calibration status to global variables for Lead Commander to read
GPS looks for sat signal and writes status to global variable
When 'all systems ready'
Lead commander gets desired destination,
*reads GPS data,
*reads object detection status
*tells steering to go to specified degree turn position,
*tells drive to go fwd (if not blocked by object)

If object is detected, tell aim/fire where to point and·when to shoot or just avoid by·commanding steering and drive.

Each of these systems (1-7) constantly look for fault situations and have their own fault routines.· The Fault Routine of a system reports the fault to Lead commander as it goes to a safe state.

Why would I want to have my prog in more than one Object?
·

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2010-06-12 19:50
    Hello Nelson,

    please change to a non military project.

    Even if it is a model tank. If you tinker around with it you directly add to the knowledge the military

    best regards

    Stefan
  • max72max72 Posts: 1,155
    edited 2010-06-12 19:50
    I usually have many objects because:
    1- It is easier to mantain (see also point 2)
    2 - you can reuse the code easily (see also point 1)
    3 - The object comes from obex, and I'm using it as it is or modified
    There are many other reasons, I'm sure, but thr main points on my side are here.

    For instance: You have a GPS, you get a working object from obex (you can also find a 1 COG object), and you are done (point 3).
    You have functions for navigation purposes, yours or from obex. It is possible you'll reuse the functions somewhere else (point 2), and you might find easier to modify/customize the funtions using a separate test program (point 1).

    Nonetheless you can have everything in a single file.... it's up to you.

    Massimo
  • cnelson700cnelson700 Posts: 31
    edited 2010-06-12 22:02
    My main concern is communication between the cogs.
    I can modify objects as easily as I can modify methods.
    I do like modularity so I like the idea of SPIN Objects - by the same token, methods are modules also. But, unless I am mistaken, variables in the VAR section are global to the object that they area declared in. In order to read/write to/from a variable by different objects, the @ddress of the variable has to be passed to the child object.

    So... Is it a good idea to use 1 object with multiple methods if your main concern is processing and fast communication between multiple cogs?


    Side Note to Stefan: Even if Military Intelligence == Oxymoron, I doubt Dennis Blair (or his TBD successor) really cares about this particular post. But if I can help our troops in any way, I will without delay.
  • John R.John R. Posts: 1,376
    edited 2010-06-12 22:45
    StefanL38 said...
    Hello Nelson,

    please change to a non military project.

    Even if it is a model tank. If you tinker around with it you directly add to the knowledge the military

    best regards

    Stefan

    Huh???

    So if he takes off the gun, and replaces it with a camera, how does this make any knowledge gained less useful in a military sense?

    I would also suspect that with very few possible exceptions, I don't think that anyone here is going to "add" to the military's knowledge base.

    I guess I'm failing to see the point of your suggestion.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.
    Click here to see my Nomad Build Log
  • Mike GreenMike Green Posts: 23,101
    edited 2010-06-12 23:54
    There's no fundamental reason why you have to break up multi-cog programs into several objects. It's really a matter of encapsulation and whether that makes the program easier to write, debug, and maintain or not. Objects are particularly useful when it's helpful to use preexisting objects that implement or support some function or specific hardware.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-06-13 00:52
    cnelson700 said...
    ....

    Autonomous Tank example

    ....

    An autonomous tank. Wow, now there's a scary concept. What happens when you try to pull its plug but it keeps on going?


    www.salon.com/news/feature/2008/10/14/friendlyfirevideo
  • cnelson700cnelson700 Posts: 31
    edited 2010-06-13 19:37
    Thanks for the answer Mike.

    __________________________

    I am not building a tank.· I just used a tank as an example of multiple processes that need to coordinate quickly and accurately.

    iRobot has military robots - http://www.irobot.com/gi/
    ·
  • max72max72 Posts: 1,155
    edited 2010-06-13 20:30
    in my list I forgot to mention point 0
    0-with objects you can share your achievements back...

    Massimo
Sign In or Register to comment.