Pages: 1 ... 13 14 [15] 16 17 ... 34   Go Down
Author Topic: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5  (Read 109940 times)
0 Members and 1 Guest are viewing this topic.
Toledo, OH
Offline Offline
God Member
*****
Karma: 35
Posts: 508
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Interesting discussion Tim.  I disagree about timestamps.  Here's how to synchronize 2 Uno's to 2us.
As you can see they stay in sync even without GPS once initialized.
http://arduino.cc/forum/index.php/topic,120288.0.html

Synchronizing two are not the issue, it's knowing when the ping was sent so you know how long it took to get there.  How do you know WHICH ping you're getting?  Without knowing when the ping was sent, how can you possibly know how long it took to get there?

Let's say that you've synced two ATmega's to within 15 microseconds (that accuracy would be plenty).  One starts sending out pings every 2 millisecond which the other would receive.  Even though they're synced, how does the receiving unit know when that ping was sent to be able to calculate the time and therefore the distance?  Without the start time reference, I can't see how you would measure distance.  For the sake of argument, the receiving unit gets the ping, what values are you using to calculate for distance?  You have receive ping time, so what's the start time?  You need both start and end time to calculate the time it took to send the ping.  You know the pings are 2ms apart, but where do you get the start time?

You *could* measure acceleration/deceleration by measuring the time between the pings.  But, that wouldn't need the two units to be time synced anyway, and would do nothing to measure distance.  Only "hotter" or "colder" would be known.

Tim
Logged

Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Let me simplify and round to make it easier to discuss.  We will use your method of only 1 unit.  First send out a single ping and wait up to 100ms.  Each 1ms is about 1ft, 2ms round trip.  Measure the integer number of msecs rounding down.  Let's assume the result is near the middle between 20-21 about 20.5.  We don't need to be more exact than that.  Now send out 100 pings exactly 1ms apart.  Measure the return values mod 1000us.  This gives us the part to the right of the decimal.  We already know 20ms.  Average them.  We might get 522us.  So the answer is 20.52ms.  The last 2 is not significant.  Convert to feet. 

You can see we don't need to identify which ping is which.  It doesn't matter since they're all sent at x.000 secs.  This could be relative to nothing, or GPS time.  But we could figure it out since we know the object is about 20.x ms away.  When a ping comes 20.51ms later we know it was sent 20+us ago, not 19 or 21.

This would not work if the object were exactly 20.01ms away, because we would hear the ping being sent each 1ms.  It would be much louder and block us from hearing the echo.  But it would work with 2 devices using an accurate clock!  Or you could just change the interval to 1.12ms instead of 1.0ms if your echo was being blocked.  More complicated math.

The advantage of my idea is that you get 100's of pings per second to average, even if the target is far away.  This will let you calculate an accurate distance much quicker than waiting 100ms between sending, if you want an answer in 0.3 secs.

If you like my idea you an have it!

Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Toledo, OH
Offline Offline
God Member
*****
Karma: 35
Posts: 508
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Let me simplify and round to make it easier to discuss.  We will use your method of only 1 unit.  First send out a single ping and wait up to 100ms.  Each 1ms is about 1ft, 2ms round trip.  Measure the integer number of msecs rounding down.  Let's assume the result is near the middle between 20-21 about 20.5.  We don't need to be more exact than that.  Now send out 100 pings exactly 1ms apart.  Measure the return values mod 1000us.  This gives us the part to the right of the decimal.  We already know 20ms.  Average them.  We might get 522us.  So the answer is 20.52ms.  The last 2 is not significant.  Convert to feet. 

You can see we don't need to identify which ping is which.  It doesn't matter since they're all sent at x.000 secs.  This could be relative to nothing, or GPS time.  But we could figure it out since we know the object is about 20.x ms away.  When a ping comes 20.51ms later we know it was sent 20+us ago, not 19 or 21.

This would not work if the object were exactly 20.01ms away, because we would hear the ping being sent each 1ms.  It would be much louder and block us from hearing the echo.  But it would work with 2 devices using an accurate clock!  Or you could just change the interval to 1.12ms instead of 1.0ms if your echo was being blocked.  More complicated math.

The advantage of my idea is that you get 100's of pings per second to average, even if the target is far away.  This will let you calculate an accurate distance much quicker than waiting 100ms between sending, if you want an answer in 0.3 secs.

If you like my idea you an have it!

Sending pings out every 1ms would be too quick as it could take up to 29ms for that ping to arrive.   A ping every 1ms would only work if you were measuring distances of less than around 34cm.  Anything further than that would require a longer time between pings.  I was assuming you were wanting to measure up to 10m (the max sensor distance).  If so, you couldn't ping faster than once every 29ms.  If you only were going to measure within 34cm, then you could send a ping out every 1ms.

And that's just the start of the problem.  Conventional ping sensors would still have a problem for three reasons.  First, when you tell a ping sensor to send out a ping, it takes it's good old time doing it.  I haven't found one that takes less than 440 microseconds (7cm worth) of waiting around before it starts.  Some can take over 88ms!  Secondly, some sensors go inactive for a while after a ping is received, or even longer if a ping is not received (like 32ms!)  Finally, existing sensors don't listen for an echo till that same sensor sends out a ping first.  In other words, the receiving sensor isn't even listening when the sending sensor is sending out pings.

Maybe I don't understand what you're trying to accomplish.  Do you want to ping 100 times a second?  You can almost do that already with the NewPing library if your sensor allows it.  Or, are you trying to make an ultrasonic sensor work for further than 5m?  And if so there are sensors that work up to 50 feet away already.  But, the technique you're speaking of would not allow you to send 100 pings per second and measure the distance from 10m away.  Pinging every 29ms for 10m or pings every 1ms for distances within 34cm would be possible.  But only with custom designed ping sensors and receivers and accurately synced devices.

I guess I just don't see what you're trying to do, as you can already ping at very high speeds with the NewPing library with sensors that support it (not quite 1ms, but every 3ms works for distances of about 50cm).  It's also a bit of an issue outside the scope of the NewPing library as you would need custom hardware and special hardware to sync the two systems.  More of a specialty thing rather than a public library.

Tim
Logged

Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got a working demo pinging every 1ms using 2 simple transducers.  The object is 10ft away.
To summarize: First you need to know how many integer feet away it is.

Sounds like I cannot use the same hardware you have with 2 units, sender and receiver.
My goal is to double my distance, as you said.

With a Quadcopter, this S/R method allows me to put the receiver on the ground away from the noisy motors and blades.
Again doubling the distance, that's >x4 compared to using a single sensor in the air.
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Toledo, OH
Offline Offline
God Member
*****
Karma: 35
Posts: 508
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got a working demo pinging every 1ms using 2 simple transducers.  The object is 10ft away.
To summarize: First you need to know how many integer feet away it is.

Sounds like I cannot use the same hardware you have with 2 units, sender and receiver.
My goal is to double my distance, as you said.

With a Quadcopter, this S/R method allows me to put the receiver on the ground away from the noisy motors and blades.
Again doubling the distance, that's >x4 compared to using a single sensor in the air.


Yes, you would need to know how many integer feet away it is.  It also wouldn't be able to detect how many integer feet away it was or if it moved position outside of a foot it wouldn't know it was at a different position.  But, what's the point of sensing the distance if you already know the integer feet and the distance couldn't vary that much?

If you simply want to double the distance, use an ultrasonic sensor that can sense up to 50 feet away.  No need to change anything else.  Or, use two sensors connected to the same Arduino with one having a 10 foot connection.  Disable the outbound ping speaker on the receiving unit and trigger both at the same time.

Not sure how it helps the Quadcopter, other than maybe to hover in place, and only when on top of the receiving sensor.  How do you know how many integer feet away it is?
Logged

Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have to first send a long ping to get the integer part.  Then the next pings come 1ms later, so it can't have moved very far.  If it does move slowly you can track it's location with only 1ms pings.  You don't have to wait for the long ping to return to begin sending more, unless you are concerned about missing the first one and not knowing it.

There are 2 new independent ideas here.  One of them is sending pings closer together like 1ms.  The other is using a separate sender/receiver, with one of them attached to the object.  You can choose one or both methods.

Yes it would only help for landing at a particular spot.  This is better than nothing because it doesn't work otherwise past 3ft.
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Toledo, OH
Offline Offline
God Member
*****
Karma: 35
Posts: 508
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have to first send a long ping to get the integer part.  Then the next pings come 1ms later, so it can't have moved very far.  If it does move slowly you can track it's location with only 1ms pings.  You don't have to wait for the long ping to return to begin sending more, unless you are concerned about missing the first one and not knowing it.

There are 2 new independent ideas here.  One of them is sending pings closer together like 1ms.  The other is using a separate sender/receiver, with one of them attached to the object.  You can choose one or both methods.

Yes it would only help for landing at a particular spot.  This is better than nothing because it doesn't work otherwise past 3ft.

I will have to bow to your better wisdom of using a quadcopter. I'm only in the research stage of building one at this point.  I had planned on possibly using an ultrasonic sensor as a type of automated landing assistance or possibly crash protection or autonomous usage.  Using an ultrasonic sensor was not paramount to my quadcopter plans (primary goal is for aerial photography/video).  But, I had not considered noise from the quadcopter interfering with the ultrasonic distancing.

Ping frequency didn't seem to be an issue as I figured the ATmega would have a lot to do with reading all the sensors/controls, calculating stabilization etc.  Also, I only had figured I'd ping to about 8 feet (250cm) where I could ping every 15ms (66/second).  With a quadcopter going 10mph (14.67 fps) that works out to about a ping every 2.5 inches.  I figured if it was moving any faster than 10mph, it would probably be moving too quickly at 8 feet to stop in time anyway.  Maybe in reality this is a naive plan, as prop noise was not considered and speed is unrealistic.  I had figured 8 feet @ 10mph would still give 2.5" of resolution.  Obviously, the quadcopter would be slowed at this point with a landing in the <3mph range which 15ms pings would mean it could only be moving about a cm per ping.  That naively seems like a realistic landing, but maybe not.

The other issue specific to a quadcopter is that the NewPing library is *NOT* currently suited to quadcopters!  While it's faster than other libraries, there's an inherent issue were even the fastest (trigger/echo) sensors will sit around waiting for about 440uS per ping.  That's just not acceptable in my opinion for a flight controller.  I have plans to make NewPing work in this situation, but currently it's not advised.  I would suggest for a quadcopter you use a I2C ping sensor that does all the calculation without waiting around for the ping to return.  Obviously, doing it your way where we just ping from the quadcopter we don't need to wait for the ping to initiate nor the ping echo to return we don't have to worry about CPU usage.  But still, NewPing is not suited for that purpose as it's a distancing library.

Your project sounds interesting, and I may very well look into this when my quadcopter is launched, but I don't think this usage will ever be integrated in the NewPing library.

Tim
Logged

Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your library is suitable if you want slow updates close to the ground before landing.  Sometimes that is all we need for a Quadcopter.

I have been flying for months.  I recommend beginning with a KK board.  It has gyros, it's simple, and it just works the first time.  KKv2.0 has accelerometers too, to keep it level.  It's hard enough to fly even with this, impossible without it the first time.

The next step is a pressure sensor to keep it steady at a particular altitude for example 10m above ground.

Then a compass to keep it pointed north, now it's easy to control the x,y position manually with only 1 stick on transmitter!
I've found a 2D compass works if you have a KK2.0 board first.

If you're still having fun add GPS.  Hobbyking has a frame and 4 motors for $30.  Let me know if you have any question!
Steve

Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Toledo, OH
Offline Offline
God Member
*****
Karma: 35
Posts: 508
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Your library is suitable if you want slow updates close to the ground before landing.  Sometimes that is all we need for a Quadcopter.

I have been flying for months.  I recommend beginning with a KK board.  It has gyros, it's simple, and it just works the first time.  KKv2.0 has accelerometers too, to keep it level.  It's hard enough to fly even with this, impossible without it the first time.

The next step is a pressure sensor to keep it steady at a particular altitude for example 10m above ground.

Then a compass to keep it pointed north, now it's easy to control the x,y position manually with only 1 stick on transmitter!
I've found a 2D compass works if you have a KK2.0 board first.

If you're still having fun add GPS.  Hobbyking has a frame and 4 motors for $30.  Let me know if you have any question!
Steve

I considered the KK due to the extreme low cost.  But, will probably go for the Crius AIO Pro because checks all the boxes and is only $63 for a ATmega2560, 10DOF (including the MPU6050), and GPS can be added for only $25.  The KK2.0 is interesting, but I want more control, not less.  Also, I decided a deal-breaker was any ATmega328p-based flight controller due to the lower bit PWM control.  The ATmega32u4 with its (6) 11-bit PWM's was considered (in the NanoWii and the Pro Micro).  But, the price is higher than the Crius AIO Pro once you add a magnetometer or flight controller to the Pro Micro.  I really like the NanoWii.  But, the price is already very close to the Crius AIO Pro and adding a magnetometer puts it over, before a altimeter is even considered.  The Crius AIO Pro is really hard to beat in price, and it's not missing anything either.

ESC's and motors are my issues now.  First I was considering the Turnigy Plush, but then I read about the SimonK firmware and found the RCTimer SimonK 30A ESC's.  But, I'm worried about the lack of an external resonator in it.  So, I'm considering a HobbyKing F-30A and flashing the SimonK firmware myself.  But, the F-30A isn't in stock, and typically hasn't been for years now ;-(

Then there's the motor issue.  Finding a quality motor that's not too expensive has been a challenge.  I read recommendations, only to read later that the model has changed or there's new quality problems.  Looking for something in the 2836/kv850 range that can drive a 1147 prop (I'm going to run Lipo 3S).  The Turnigy 2217/860kv seems like a good motor, and I can get 4 for only $58.

I'd like to get everything from one place, but it's starting to look like I'm going to be making a few different orders.  Suggestions?

Tim
« Last Edit: August 29, 2012, 02:39:30 am by teckel » Logged

Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I like your choices will read about Crius.  I'm going low cost.  ESC for $6.  Motors for $7 for my first model.  Ebay or Amazon free shipping.
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I agree, Crius seems like the best choice.  It's new and complicated inside.  But not many people have tested it in the real world.  The code is new too.  A small bug might cause a crash if you're not an experienced Quad pilot.
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Toledo, OH
Offline Offline
God Member
*****
Karma: 35
Posts: 508
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I agree, Crius seems like the best choice.  It's new and complicated inside.  But not many people have tested it in the real world.  The code is new too.  A small bug might cause a crash if you're not an experienced Quad pilot.

The AIO had one hardware issue, which has since been resolved (weak USB connector).  Software-wise, it's just using MultiWii, and nothing special as it's all standard hardware with standard connections.  To MultiWii, it's just a ATmega 2560 with a 6050 and other sensors attached.  Not saying there couldn't be a problem, but those that have it have had success and it's been out for a few months now so there's a lot of them out there.  There's been a couple with problems, but problems with vibration and losing a radio connection can be found for every flight controller (as it's the fault of something else, like unbalanced motor or a cheap radio).

It's not Crius' first flight controller either.  So, they've had some experience.  Finally, nothing they're doing is revolutionary.  They just print up a board connecting very common chips together in common ways.  Really, all Crius did was make traces between very common and well documented processors/chips.  It's only $60, if it was $300 from some unknown I'd reconsider.  Heck, a branded Arduino Mega is almost $60 with 0DOF.

Tim
« Last Edit: August 30, 2012, 11:15:28 pm by teckel » Logged

Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 4
Posts: 195
Anything is possible
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does this library works with URM37 v3.2 ( http://www.dfrobot.com/wiki/index.php?title=URM37_V3.2_Ultrasonic_Sensor_(SKU:SEN0001) )

Mode 3: PWM passive control mode
Under this mode, a low pull on pin COMP/TRIG will trigger a sensor reading. The width of the pulse is proportional to the servo rotating degree. After a successful sensor reading, Pin PWM will output pulses, every 50us represents 1cm. If the reading is invalid, a 50000us pulse will be returned.

Can I use the NewPing library and change the NewPing.h to make it work for the URM37 v3.2 ?

Thanks
Logged

Toledo, OH
Offline Offline
God Member
*****
Karma: 35
Posts: 508
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does this library works with URM37 v3.2 ( http://www.dfrobot.com/wiki/index.php?title=URM37_V3.2_Ultrasonic_Sensor_(SKU:SEN0001) )

Mode 3: PWM passive control mode
Under this mode, a low pull on pin COMP/TRIG will trigger a sensor reading. The width of the pulse is proportional to the servo rotating degree. After a successful sensor reading, Pin PWM will output pulses, every 50us represents 1cm. If the reading is invalid, a 50000us pulse will be returned.

Can I use the NewPing library and change the NewPing.h to make it work for the URM37 v3.2 ?

Thanks

Reading the documentation, it appears that it will work with the NewPing library.  It does appear that you would need to change the US_ROUNDTRIP_CM to 50 and US_ROUNDTRIP_IN to 127 for the distance calculations to be correct.

With that said, if you don't already have the URM37 and there's not a good reason why you need to buy this specific one, I would suggest getting one that's known to work with NewPing.  As a bonus, they're also cheaper than the URM37.

Further, if it was me, and I already had this sensor or was required to use it for another purpose, I would use the serial interface instead of the trigger/PWM interface.  There's many benefits of using the serial interface, including setting up automated pings, not waiting for ping echos, getting temperature, etc.  They've also created a serial library for the sensor so you don't need too much effort to get it working in this way.

If you do get the sensor working with NewPing, let me know.  I'd like to hear your experience.

Tim
Logged

Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This may have been answered before in the thread, but I didn't see it on a quick read-through.

I'm using the NewPing library (which is awesome) and the Arduino Motor Shield.  Unfortunately the shield uses pins 3 and 11 to do the motor PWM, which conflicts with Timer2 used in NewPing.

Is there a way to change what timer NewPing uses?  Or, is it just simpler to un-stack the shield and the Arduino and manually wire the PWM into different pins?
Logged

Pages: 1 ... 13 14 [15] 16 17 ... 34   Go Up
Jump to: