To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.trainsOpen lugnet.trains in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Trains / 22381
22380  |  22382
Subject: 
Re: control train using rcx
Newsgroups: 
lugnet.trains
Date: 
Thu, 12 Feb 2004 14:22:31 GMT
Viewed: 
1999 times
  
In lugnet.trains, Steven Brown wrote:
Hi im going to be turning the potentiometers by hand to control the motor of the
train.  Should i be stepping down the motor voltage will that make any
difference?, i will be using the hall effect device on the sensor input of the
rcx and it will detect the train and hopefully stop it.  Just not too sure how
to start programing the controls for increasing the speed and controlling the
brakes.

If you have a potentiometer wired between the RCX motor output and the track,
you can use it to control the maximum train speed.  This could be helpful, since
a train running at the RCX's normal full motor speed is usually going pretty
fast.  You can then use the eight RCX motor power levels to control the speed of
the train.  In NQC, you would do something like this:


  // To start the train at a medium speed:
  int speed = 4;  // Set 'speed' to a value in the range 0...7
  SetDirection(OUT_A, OUT_FWD);
  SetPower(OUT_A, speed);
  SetOutput(OUT_A, OUT_ON);  // Start the train

  // To change the speed:
  speed = 7;
  SetPower(OUT_A, speed);

  // To stop the train, allowing it to coast:
  SetOutput(OUT_A, OUT_FLOAT);

  // Or, to slam on the brakes:
  SetOutput(OUT_A, OUT_OFF);

To mimic inertia, you might do something like this:

  int speed;

  // Start the train:
  SetDirection(OUT_A, OUT_FWD);
  SetPower(OUT_A, 0);
  SetOutput(OUT_A, OUT_ON);
  for (speed=0; speed<8; speed++)
  {
    SetPower(OUT_A, speed);
    Wait(50);  // Wait 1/2 second between power level changes
  }

  Wait(1000);  // Run the train for 10 seconds

  // Stop the train:
  for (speed=7; speed>=0; speed--)
  {
    SetPower(OUT_A, speed);
    Wait(50);
  }
  SetOutput(OUT_A, OUT_FLOAT);

This is very rough, but it should give you an idea of how to start.  Of course,
you'd have to add more code to monitor your hall effect sensor and kill power to
the train if necessary.  Have fun, and please let us know how you make out.

- Chris.



Message is in Reply To:
  Re: control train using rcx
 
Hi im going to be turning the potentiometers by hand to control the motor of the train. Should i be stepping down the motor voltage will that make any difference?, i will be using the hall effect device on the sensor input of the rcx and it will (...) (21 years ago, 12-Feb-04, to lugnet.trains)

4 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR