elliottbolzan
Posts: 6
Joined: Sat May 04, 2013 4:55 pm

Timer: Photocell or Distance Sensor ?

Sun May 05, 2013 3:20 pm

I'm trying to create a system that will precisely time sprints on a track (100M probably the main distance being timed). The Raspberry Pi will emit a sound, and 100M later, a sensor will be set off by the runner. The difference in time between both of these events will then be recorded.

However, there are several issues. I'm looking for hundredth of a second precision. Can the Pi itself offer this kind of precision ?
Secondly, I'm trying to decide which sensor to use. The obvious component would be a photocell and a laser beam; this being said, I'm not certain photocells have an adequate response time. Additionally, they need another component, the laser. Meanwhile, distance sensors (http://www.pololu.com/catalog/product/136) have a decent response time (38+-4ms), but they only have a range of approximately 10-80cm.

Finally, independently of which sensor is used, a least one wire will have to run 100M. Is there any drawback to this ?

Thanks for reading, and please comment if you have suggestions ! If you know of other methods, I'd love to hear about them.

geekinthesticks
Posts: 97
Joined: Fri Feb 08, 2013 7:22 pm

Re: Timer: Photocell or Distance Sensor ?

Sun May 05, 2013 6:10 pm

It might be simpler to use two Pi's. One at the start and one at the finish. I would guess that 100m in the open would be OK for WiFi comms between the two units. One approach would be to write the start and finish times either in a text file or in a database on one of the Pi's. If you have access to the Internet using NTP should keep the two Pi's clocks in close enough sync.

elliottbolzan
Posts: 6
Joined: Sat May 04, 2013 4:55 pm

Re: Timer: Photocell or Distance Sensor ?

Sun May 05, 2013 6:21 pm

Thanks for the suggestion. It sounds great, but I'm afraid I won't be able to use WiFi, or have any other connection to Internet. Any other ideas ?

geekinthesticks
Posts: 97
Joined: Fri Feb 08, 2013 7:22 pm

Re: Timer: Photocell or Distance Sensor ?

Sun May 05, 2013 6:42 pm

The Pi doesn't contain a real time clock, although you can buy add on boards. So as a minimum you would probably require an RTC board. You should be able to communicate between two Pi's using just a standard WiFi dongle, without requiring any other equipment. Essentially, you set one Pi up as an access point and then allow the other one to communicate with it.

Don't know how accurate addon RTC's are. However, standard computer clocks only tick about 18.6 times per second, so are not very accurate. If you can somehow interface with a GPS unit, that would give you very accurate time.

kaos
Posts: 108
Joined: Mon Mar 26, 2012 8:14 pm

Re: Timer: Photocell or Distance Sensor ?

Mon May 06, 2013 12:39 pm

Re: Timing accuracy. I haven't any experience myself of timing critical projects, but from what I have read, this might be borderline if you need +/- 10mS accuracy, assuming a Raspi running Linux and without any additional circuitry. Hopefully somebody with more experience will chime in on this. If it turns out it is not accurate enough, helper circuitry in the form of a PIC or AVR chip should do the trick.

Re: Real time clock. The Raspi does have a RTC; what it lacks is battery backed RTC. This means that, if the clock is not set after each boot, either manually or with the help of an NTC server, the date and time will be incorrect. It is still perfectly capable of measuring elapsed time; it just won't be able to tell you if this period occurred in the Jurassic or today.

Re: Sensors. I would be disinclined to use distance sensors for this, not only because of the limited sensing distance, but also because of the diffuse sensing zone; it would be difficult to define a sharp and repeatable finish line. A visible-wavelength laser has the advantage of being a line. I agree that the standard LDR (light dependent resistor) photocell has too slow response time, but you can also get semiconductor light sensors that are much faster. There is one such at the bottom of this page, http://www.futurlec.com/Photocells.shtml, but other might be better suited for this application; this is just an example I remembered coming across before.

Re: Distance. 100m should be quite doable via twisted pair cable, such as telephone or network cable. The problems with long wire runs are, on the one hand signal attenuation due to wire resistance, and on the other hand susceptibility to interference. By using moderate current (in the range of 2 to 20 mA) over twisted pair wire, there should be no problem. Radio might make for easier setup, but the delay inherent in WiFi communications might be too high. Simpler radio modules like some of these, http://www.futurlec.com/Radio.shtml, should have lower propagation delays. (And no, I don't have any connection with Futurlec except as a satisfied customer; they're just my first port of call when looking for electronic components :-) .)

Hth, Kári.

User avatar
Burngate
Posts: 6067
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Timer: Photocell or Distance Sensor ?

Mon May 06, 2013 5:05 pm

No thoughts regarding timing, sensing etc., but if you put the Pi at the finish line, all you need to send to the start is the sound. That'll get 100M with no problem - RF pick-up and so on won't affect it, and since you'll need some amplification anyway if you're planning on using the 3.5mm jack output, 100M of reasonable two-core mains cable with a speaker on the end should work.


EDIT:
Each time I read your original post,
a least one wire will have to run 100M
I keep wondering if a wire can run as fast as a sprinter?

elliottbolzan
Posts: 6
Joined: Sat May 04, 2013 4:55 pm

Re: Timer: Photocell or Distance Sensor ?

Tue May 07, 2013 6:53 pm

I've decided to go the wireless way, with two Pi's or a Pi and an Arduino. I imagine I could have communication between both devices before the run, and calculate the average transfer time; I could then just subtract this from the final speed.

Thanks for suggesting a semiconductor light sensor as well ! If I'm understanding this datasheet (http://www.futurlec.com/Light_Sensor.shtml) correctly, this particular sensor has a ~10ms response time. Is this the case ? If so, that's just what I need.

I was thinking of using this transmitter (https://www.sparkfun.com/products/10534) and its corresponding receiver. Sparkfun says the range is 500ft, which is approximately 150 meters (this is in perfect conditions); I imagine a track corresponds to "perfect conditions". However, would it be simple to interface an Arduino and a Pi using these components ?

Thanks to everyone for the help.

User avatar
joan
Posts: 14391
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Timer: Photocell or Distance Sensor ?

Tue May 07, 2013 7:04 pm

I don't see you guaranteeing 1/100th of a second precision with the setup as far as I understand it. Could you clarify the timeline of events? i.e. what triggers the start and how does information flow between the components?

elliottbolzan
Posts: 6
Joined: Sat May 04, 2013 4:55 pm

Re: Timer: Photocell or Distance Sensor ?

Tue May 07, 2013 7:09 pm

Pi sends 100 packets of data to Arduino, and waits for responses. Calculates the average one-way travel time between both devices.
User presses button on Arduino to arm timer. Pi is notified.
Pi (after a delay), sends the command to the Arduino to play a sound through a Piezo. The time at which this command is run is recorded.
Arduino plays sound. Runner starts.
Runner crosses Linear Light Sensor, and triggers end mechanism on the Pi.
Pi subtracts the time recorded earlier to the final time.
Additionally, Pi subtracts the average travel time.
Pi displays results on a small screen.

I could live with less than 1/100 of a second precision, but anything above 1/20 of a second makes the project lose its purpose. Do you think this is a viable process ?

User avatar
joan
Posts: 14391
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Timer: Photocell or Distance Sensor ?

Tue May 07, 2013 7:28 pm

elliottbolzan wrote:...
I could live with less than 1/100 of a second precision, but anything above 1/20 of a second makes the project lose its purpose. Do you think this is a viable process ?
I don't think it's viable from the Pi running Linux using the normal system processes. You have no way of accurately time-stamping information entering or leaving the Pi. You can time-stamp when you told a Linux process to transmit data and when you received data from a Linux process. You can't tell how long it took to get between a Linux process and the Pi's hardware.

elliottbolzan
Posts: 6
Joined: Sat May 04, 2013 4:55 pm

Re: Timer: Photocell or Distance Sensor ?

Tue May 07, 2013 7:44 pm

Ah, I understand your point. Well, in the case of wireless transmissions, this won't be a problem: the time taken for the software to interface with the hardware will be included in the average travel time.

However, I can see how this could be an issue with the sensing at the finish line. The good news is this particular sensor has a response time smaller than 10ms; I don't expect Linux's reading of the data to take much longer itself.

Are there any benchmarks regarding software and hardware communication on the Pi ?

User avatar
joan
Posts: 14391
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Timer: Photocell or Distance Sensor ?

Tue May 07, 2013 7:55 pm

I've seen Linux processes frozen out for a tenth of a second.

I'm dubious of averaging message propagation times. If 50 take 0.4 seconds and 50 take 0.2 seconds you get an average of 0.3 seconds. Each message time is still 0.1 seconds wrong.

geekinthesticks
Posts: 97
Joined: Fri Feb 08, 2013 7:22 pm

Re: Timer: Photocell or Distance Sensor ?

Tue May 07, 2013 8:14 pm

I have probably had too many glasses of wine but...

You can record a timestamp when your process requests information from hardware, then another timestamp when you get a reply. Similarly, you can record a timestamp when you send a packet via Wifi and then when you receive the packet back. This is sort of how the SMTP time syc protocol works. You send a TCP packet with a timestamp, the receiving end timestamps the packet and sends it back. You can then work out how long the packet took being transmitted backwards and forwards.

Anyway, I need another glass of wine...

elliottbolzan
Posts: 6
Joined: Sat May 04, 2013 4:55 pm

Re: Timer: Photocell or Distance Sensor ?

Tue May 07, 2013 8:23 pm

Thanks geekinthesticks, that's pretty much what I'm trying to implement (except all the timestamping will take place on one device, to minimize error).
Concerning Linux freezing up for a tenth of a second, I should be able to minimize the issue by running nothing else on the board. And I guess, worse case scenario, there will be a tenth of a second delay (although even that seems large, but I've never played with the Pi before).
Obviously, averaging the message times is not an ideal solution. However, in the same exact conditions, gathering a certain amount of pre-run tests should give a relatively good value. I mean, the waves will be able to travel in the exact same manner every time.
Furthermore, I'd rather the timer be off by 0.1 every time, than it be off by 0.4 or 0.2 ( if I don't account for the time it takes to transmit).

Overall, thanks to everyone for their input in this thread, I've definitely gotten a good idea of which direction to go towards !

Return to “Automation, sensing and robotics”