On Monday 12 Jan 2004 9:48 pm, James Edward Gray II wrote:
> On Jan 12, 2004, at 2:42 PM, Rob Dixon wrote:
> > Hi Gary.
> >
> > I'm quite concerned about this thread. I think we could help you a
> > lot more if we had a better grasp of the problem: instead we've been
> > answering individual questions that you've raised, hoping that they
> > help you to achieve your goal but without any real idea of where
> > you're headed.
>
> and
>
> > Finally, throughout this thread we've been working with our imaginings
> > of your design and code. It would help you as well as the group if you
> > were to post some actual code - this will be much more descriptive of
> > your ideas than you may imagine, and will help us to address the real
> > problems you're facing.
>
> Rob's always so much smarter than I am. Darn him! :P
>
> I just wanted to say that I think this is an excellent idea. I think
> if you could get across to us how a small Trainset works on minimal
> level (using each of your objects once or twice), we might be able to
> critique code you provide or roll some of our own. I bet you would
> learn a lot more for that than all these guesses we've been making,
> just like Rob said.
>
> James
The primary purpose of this excercise is to learn OOP and for this reason I'm
taking on board the comments passed in these threads, including creating a
Trainset object and moving the other object types into seperate
classes/packages - more below.
The purpose of the Trainset is to allow a railway to be modelled on a
computer.
Initial uses are:
* to emulate and eventually control a OO guage model train set.
* to provide a training environment to train signalmen.
* Possibly combine the both to allow training of signalmen through the use of
a model train set.
I am currently learning to be a locomotive fireman on the North Yorkshire
Moors Railway, a 18 mile preserved steam railway in North Yorkshire, England.
On this railway are 4 quite complex signalboxes, the biggest one covering
Grosmont station and approach has 3 platforms, 32 signals and 52 levers. At
any one time we can have 3 8-coach service trains running, plus other
shunting activities goining on within station limits.
As you can imageine, it takes a very long time to be passed out as a
signalman, and each person has to be passed seperately for each box.
I intend to build a Hornby OO guage model of the railway in the loft once I
get time :), and would like a method of being able to run the full service
over the model. I therefore need a means of automating the control of the
signals, points etc., as well as being able to drive the trains.
The ultimate goal would be to have a model of a signalbox's control space, and
then connect that to the PC on which a signalman is being instructed. I
believe that the visual feedback would aid the training. (It would also be a
great interactive display for the general public).
Now that I've given a glimpse at my goal, here's a glimpse of what I've
gleened from these threads.
1) I'm going to organise the modules as:
Trainset.pm
Trainset/Track.pm
Trainset/Points.pm
Trainset/Signals.pm
Trainset/Levers.pm
Trainset/Boxes.pm
2) I'm going to create a Trainset object and have the instance own everything
else
3) As everything else will be created from the Trainset instance, they will
have a link to it. This will be stored as $self->{_OWNER}. This will then
(hopefully) provide quick direct access to the Trainset variables (were Class
globals). I think I should be able to simply call something like
$self->{_OWNER}{_BLOCKS}
The example code (not tested yet) will create a long length of track (TCB1 and
TCB2), and a siding (S1). It will then create a switch (Y-shape) point and
connect that to TCB2 and S1.
It will then create a signalbox, and in that signalbox create a lever to
control the set of points.
my $tset=Trainset->new;
$tset->add_track('TCB1','TCB'); # create 1st block of track
$tset->add_track('TCB2','TCB'); # create 2nd block of track
$tset->add_track('S1','TCB'); # create Siding 1
$points=$tset->add_point('GSP1','SWITCH'); # create switch point to siding
$tset->add_link('TCB1',0,'TCB2',0); # link TCB1 (rear) to TCB2 (advance)
$tset->add_link('TCB2',0,'GSP1',0); # link TCB2 to points GSP1
$tset->add_link('S1',0,'GSP1',1); # link Siding1 to points GSP1 (offset1)
$box=$tset->add_signalbox('Grosmont'); # Create Grosmont signalbox
$lever=$tset->add_lever('GS1'); # Create lever GS1
$box->use_lever($lever,0); # Put lever1 in signalbox
# would be nice if I could replace the above with a shortcut like
# $box=$tset->add_signalbox('Grosmont'); # create signalbox
# $lever=$box->add_lever('GS1',0); # create lever and put in s'box
$lever->set_use(0,$points,'TCB2'); # position 0 = select TCB2
$lever->set_use(1,$points,'S1'); # position 1 = select S1
$lever->throw(0); # throw lever
I hope that this has shown (a) what I am hoping to aim for with this project
and (b) that I've taken on board the comments and hopefully implemented the
suggestions correctly.
Now the new questions.
1) I've put:
use base (Trainset::Trains Trainset::Track Trainset::Signals
Trainset::Levers Trainset::Boxes);
inside Trainset.pm. Is this the correct way to call in the other classes? If
so, would this also give Trainset::Boxes access to
Trainset::Levers::add_lever to enable the shortcut I mentioned above?
2) What I do with the data will obviously depend on the program using my
object, but would probably be things like update the screen (Term, TK,
Win32), or to send instructions to a control system (e.g. throw points on
model railway).
What is the best method to pass control back to the program from within a
method?
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>