javelin stamp sensors
DakDuif
Posts: 8
Hello,
I'm a 3th years college student on the MBO nv. 4 on ROC Zadkine Spijkenisse in the Netherlands.
We recently had an assesment to create a traintrack in which we got sensors that check how fast the train goes
I need to check now how to convert the·time between 2 sensors (point 1 and 2) to speed (KMPH)·
Any hints
Cheers,
Dave Koekebacker
I'm a 3th years college student on the MBO nv. 4 on ROC Zadkine Spijkenisse in the Netherlands.
We recently had an assesment to create a traintrack in which we got sensors that check how fast the train goes
I need to check now how to convert the·time between 2 sensors (point 1 and 2) to speed (KMPH)·
Any hints
Cheers,
Dave Koekebacker
Comments
Timer t = new Timer();
int time,speed;
while (true) {
· while (!train_passed_sensor1) ; //wait until train passes sensor1
· t.mark();
· while (!train_passed_sensor2) ; //wait until train passes sensor2
· time = t.passedMS(); //passed milliseconds
· speed = distance/time; //distance is distance between sensor1 and sensor2
}
You need to specify how sensors registrate a train passing by.
This could be a low pulse while train passes, it could also be a sticky value
with a second pin resetting the sensor.
regards peter
cheers
Dave Koekebacker
Timer t = new Timer();
int time,speed;
while (true) {
· while (!train_passed_sensor1) ; //wait until train passes sensor1
· t.mark();
· while (!train_passed_sensor2) ; //wait until train passes sensor2
· time = t.passedMS(); //passed milliseconds
· speed = distance/time; //distance is distance between sensor1 and sensor2
}
·
It is located in folder %path%\lib\stamp\core
The original Timer class does not have the passedMS() method.
You will find that in my adapted Timer class located here:
http://tech.groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/
You will also find the Timer16 class and ScaledTimer16 class.
These provide you with a userdefined time unit and utilize only 16bits
which is easier to handle than the 32bits of the Timer class.
For your application, the StopwatchScaledTimer16 class may be of interest.
It allows you to pause and restart, accumulating time.
regards peter