Integration of SRF08 I2C sonar sensor (done)

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by LuFa »

Hey ,

can you tell my how to read 2 of SRF08 ?

i think with this function :

Code: Select all


Sonar1 = srf08_ctx.range[0]; // Sonar 1
Sonar2 = srf08_ctx.range[1]; // Sonar 2



is that right ?

Thanks

alexmos
Posts: 108
Joined: Tue Aug 09, 2011 12:12 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by alexmos »

I am impressed about functionality of SRF08! Now I think it's price resonable. When you finished implementation to code I will buy one to try :)

About my code: I have found a big problem in my sonar-baro fusion: if sonar gives wrong altitude (due to noise in power), my copter have tend to go very quickly to infinite altitude :) This is because baro is tweaked by sonar and there is no diff control. I am planing to constrain sonar-baro error by 2-meter window. If error goes outside this window - no more trust to sonar and we should completely switch to baro. I will add it to r16 of my branch with many other improvements.

Waldmensch
Posts: 31
Joined: Sat Dec 31, 2011 12:10 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Waldmensch »

You could use a frame which reflects the range of the sensor -
- 26cm to 500cm. Each value outside = wrong
- >50cm while arming = wrong (through that my copter is 15cm over ground in total the sonar delivers wrong, I'm not able to mount it 26cm over ground)

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by LuFa »

can anyone upload the newest 2.0 with the SRF08 code ?

boke
Posts: 11
Joined: Sat Aug 13, 2011 1:36 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by boke »

Hello i have a SRF08 and a Wiicopter! I did download the new Dev-version but how did this work together? The sonar is blinking but i dont get anything in the GUI. What i have to to? And why do nobody test it? I saw videos from feb. Where it works now its may and nothing?
Please help me!

Andi
Posts: 4
Joined: Fri Jun 24, 2011 1:15 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Andi »

Hello,
can someone help me
I installed and activated the SRF08 in the DEV20120528.
SRF08= the red LED flashes.
Where can I see in the GUI, if the sensor is working properly?
I do not mean that he does
My System = flyduino Megaboard with Drotek 10DOF Mpu

Andi

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Tommie »

Look at the debug3 label at the bottom of the screen. It should display the distance between sensor and ground.

Katch
Posts: 280
Joined: Thu Aug 04, 2011 1:44 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Katch »

Is there a good source for this SRF08 sensor - I can't seem to find any.

I found this sensor though;

http://www.ebay.co.uk/itm/150723212509

Looks to be in spec - think it would work with the same code?

Andi
Posts: 4
Joined: Fri Jun 24, 2011 1:15 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Andi »

Tommie wrote:Look at the debug3 label at the bottom of the screen. It should display the distance between sensor and ground.



Hi , thx Tommie

ok , he works.

One more question:

How does the sensor, the signal is mixed with the Barosignal or how does it work?
PID setting with ALT for the sonar sensor?

@ Katch

I bought my here

http://www.nodna.de/Produkte/Sensoren/D ... 77f7e75558

Andi

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Alexinparis »

There is currently no code in the dev version to support the sonar output (except for plotting it)
But there is already some code working from alexmos.

Andi
Posts: 4
Joined: Fri Jun 24, 2011 1:15 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Andi »

oh
when it is planned that this works? Sonar switched with AUX without Baro in a first step that would be great
I can not program. I can only test or something for the project donations

Andi

jgrouse
Posts: 5
Joined: Thu Jun 14, 2012 12:20 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by jgrouse »

Hi,

I'm having a tough time reading through the posts where all this is at in the current 20120606 dev code (2.0)? I can see limited references to SonarALT in the code and I can get my SRF02 to show the distance in the debug value in the Config app however that's as far as it made it in the current dev code.

Is there a recent chunk of code someone has working with V2 dev code they can post here so I can test it out?

Thanks,

John

PonyoFS
Posts: 10
Joined: Thu May 19, 2011 3:05 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by PonyoFS »

Hi,
Do you know what I2c speed is supported by the srf08 ?

Thanks.
Antony.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Alexinparis »

PonyoFS wrote:Hi,
Do you know what I2c speed is supported by the srf08 ?

Thanks.
Antony.

400kHz is fine with it

PonyoFS
Posts: 10
Joined: Thu May 19, 2011 3:05 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by PonyoFS »

Thanks Alex.

Tonight i tested it on a multiwiicopter board (V4r5) with a freeimu 0.43 and a navigatron V2 GPS. Nothing to do, the sonar freezes my sensors. No flashing led on it, and on the GUI, sensors are crazy !
Anyone has a solution?

PonyoFS
Posts: 10
Joined: Thu May 19, 2011 3:05 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by PonyoFS »

I have the solution, on the multiwiicopter board V4r5, HV i2c bus is powered by the esc when you have separated power... Sorry. :oops:

But i have another problem, address of the srf08 is fixed on 0xF2 (1 long flash and 9 short flashes) and i don't know why. And nothing happened on the GUI.
Do you have a solution ?

PonyoFS
Posts: 10
Joined: Thu May 19, 2011 3:05 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by PonyoFS »

Nobody ?

Raptor
Posts: 1
Joined: Sat Jan 05, 2013 10:41 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Raptor »

PonyoFS wrote:I have the solution, on the multiwiicopter board V4r5, HV i2c bus is powered by the esc when you have separated power... Sorry. :oops:

But i have another problem, address of the srf08 is fixed on 0xF2 (1 long flash and 9 short flashes) and i don't know why. And nothing happened on the GUI.
Do you have a solution ?


I have an answer for you on this question I know its an old post, but i thought if someone else was looking at this sensor and did a search, they might find this.

Any ways mine was fixed on 0xF2 as well. the I2C bus uses only the high 7 bits for the address info, so 0xf2 becomes 0x79. I modified the orgional code defining the default address to 0x79 and the moved address to 0x78 and uploaded. See below/ Once i did that it works like a charm. When i left the second one at 0xf0 i got some large negitive number.

#if !defined(SRF08_DEFAULT_ADDRESS)
#define SRF08_DEFAULT_ADDRESS 0x79 /This was 0x70.
#endif


#if !defined(SRF08_SENSOR_FIRST)
#define SRF08_SENSOR_FIRST 0x78 // the first sensor i2c address (after it has been moved)
#endif

PonyoFS
Posts: 10
Joined: Thu May 19, 2011 3:05 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by PonyoFS »

Thanks a lot !!!!!!!!!! :-)
You make me very happy !

This sensor is in a dusty box since my question.

PonyoFS
Posts: 10
Joined: Thu May 19, 2011 3:05 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by PonyoFS »

Does anyone still working on this sensor?

mehranpour
Posts: 2
Joined: Sat Feb 16, 2013 10:56 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by mehranpour »

can i running altitude holding just with sonar?
without baro?

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by copterrichie »

mehranpour wrote:can i running altitude holding just with sonar?
without baro?


Only up to 9 feet but more like 6 feet is realistic. However, Sonar is not fully functional in the official release.

User avatar
farzadsw
Posts: 10
Joined: Tue Mar 19, 2013 8:20 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by farzadsw »

mehranpour wrote:can i running altitude holding just with sonar?
without baro?

Yes you can! :D
I'm using multiwii 2.2 source code, and I just changed a few lines in code to make altitude holding based on a sonar (SRF08) sensor possible.
First of all, you need to get valid data from sonar sensor (SRF08 or 02). Although 2.1 and 2.2 versions of the code have essential routines for SRFx sensors, There are some small mistakes in original source code, see this:
http://www.multiwii.com/forum/viewtopic.php?f=8&t=3212&start=60#p33293
Also, if your sonar sensor (SRF08) is not working as expected in long ranges, you can tune "Range" and "Gain" values to get a valid data. I limited the measurement range to about 3 meters and lowered the gain to ignore weak echoes, by adding two lines to "Sonar_init()" routine:

Code: Select all

i2c_writeReg(SRF08_SENSOR_FIRST, SRF08_LIGHT_GAIN, 0x45);  delay(50); // range= 3m 
 i2c_writeReg(SRF08_SENSOR_FIRST, SRF08_LIGHT_GAIN, 0x18);  delay(50); // analogue gain

Now you will get valid data. If data is not completely reliable, you cannot use it for altitude hold. By some tuning, both SRF02 and SRF08 sensors will provide you altitude data but compared to SRF02, SRF08 is more robust! for example, my SRF02 sometimes generates random numbers above floors with a carpet on it.
By replacing baro Altitude with sonarAlt in line 284 of IMU library, you will have sonar altitude hold:

Code: Select all

 EstAlt = (EstAlt * 6 + sonarAlt * 2) >> 3;

good luck
Farzad

dronius
Posts: 3
Joined: Wed May 22, 2013 9:58 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by dronius »

Hi guys, I was trying to get SRF10 sensor to work with MultiWii 2.2 codebase, but found some issues. Not sure how it was supposed to work at all. Perhaps there were some untested parts that got merged in from original implementation? Or perhaps it's just me being not familiar with MultiWill code.

Anyway, got it to work, the main problem was 7-bit vs 8-bit addressing on I2C. See patch attached, should also work with SRF08 and friends.
Note that SONAR_MULTICAST_PING is commented out, check if your sensor supports that (mine doesn't it seems)

I'm also thinking to play with altitude stabilization whenever sensor signal looks reliable and altitude is <= 3m. Above threshold, it would rely on barometer. Alternative is to have mixed contribution of sonar + barometer data into altitude calculation within certain "band". E.g. <= 2m 100% is taken from sonar, and >= 4m 100% is barometer. Inbetween, it's linear.

What is the process of contributing to MWC mainline?
Attachments
srf10-patch.zip
(1.23 KiB) Downloaded 366 times

felixrising
Posts: 244
Joined: Sat Mar 23, 2013 12:34 am
Location: Australia

Re: Integration of SRF08 I2C sonar sensor (done)

Post by felixrising »

Hi Dronius,

Did you get your patch included? After some discussion over at the 2.3 wishlist http://www.multiwii.com/forum/viewtopic.php?f=7&t=3167&start=40#p36647 regarding patch submission process, I'll draft something up on the wiki.. there is also some documentation about the same in the google code repo here: https://code.google.com/p/multiwii/source/browse/trunk/README.txt

Mazz1
Posts: 3
Joined: Sat Jun 15, 2013 9:19 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Mazz1 »

farzadsw wrote:
mehranpour wrote:can i running altitude holding just with sonar?
without baro?

Yes you can! :D
I'm using multiwii 2.2 source code, and I just changed a few lines in code to make altitude holding based on a sonar (SRF08) sensor possible.
First of all, you need to get valid data from sonar sensor (SRF08 or 02). Although 2.1 and 2.2 versions of the code have essential routines for SRFx sensors, There are some small mistakes in original source code, see this:
http://www.multiwii.com/forum/viewtopic.php?f=8&t=3212&start=60#p33293
Also, if your sonar sensor (SRF08) is not working as expected in long ranges, you can tune "Range" and "Gain" values to get a valid data. I limited the measurement range to about 3 meters and lowered the gain to ignore weak echoes, by adding two lines to "Sonar_init()" routine:

Code: Select all

i2c_writeReg(SRF08_SENSOR_FIRST, SRF08_LIGHT_GAIN, 0x45);  delay(50); // range= 3m 
 i2c_writeReg(SRF08_SENSOR_FIRST, SRF08_LIGHT_GAIN, 0x18);  delay(50); // analogue gain

Now you will get valid data. If data is not completely reliable, you cannot use it for altitude hold. By some tuning, both SRF02 and SRF08 sensors will provide you altitude data but compared to SRF02, SRF08 is more robust! for example, my SRF02 sometimes generates random numbers above floors with a carpet on it.
By replacing baro Altitude with sonarAlt in line 284 of IMU library, you will have sonar altitude hold:

Code: Select all

 EstAlt = (EstAlt * 6 + sonarAlt * 2) >> 3;

good luck
Farzad



Hello! do you know if i can use this metod with "i2c gps nav" sonar? i have HC-SR04 and i want sonar alt hold.
Sorry about my english, thank you!

PolyGONtrauma
Posts: 2
Joined: Sun Aug 18, 2013 4:28 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by PolyGONtrauma »

Since my SRF08 is working accurately in debug-window, I wanted to implement the baro/sonar fusion code mentioned on the first page. Unfortunately, the file "MultiWii-V1_9_alexmos_guru.zip" does not exist any more on the server. Is there any way to get the code?

Pat1300
Posts: 12
Joined: Fri Aug 03, 2012 11:31 am
Location: Wavre - BELGIUM

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Pat1300 »

Hi PolyGONtrauma,
Last version of alexmos baro/sonar fusion is avaialbel in MultiWii2_0_alexmos_r23.zip : https://code.google.com/p/multiwii-alexmos/downloads/list
Good luck with the merge !
Patrick

kavehslt
Posts: 11
Joined: Tue Jan 01, 2013 6:04 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by kavehslt »

hi everyone

my sfr08 does not work correctly. i change the address to true one like raptor said before ( i have (1 long flash and 6 short flashes) means EC in hex address and i change it to 0x76)) but i don't see any effect in my multiwii config program raptor said by enabling debug 3 we should see the effect but i don't see any thing and i2c error happen after 15-18 second !!!!!! i really confused because when i used HMC5843 with my srf08 from the beginning the i2c error happen.

Please Help me

i used independent sensors

mpu6050 + hmc5843 + MS561101BA + SRF08
and multiwii 2.2. i test all this ways with MultiWii_dev_2013_10_28_r1604 and i give the same result too.

SOS!!!!!! :? :roll:

kavehslt
Posts: 11
Joined: Tue Jan 01, 2013 6:04 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by kavehslt »

HELLO WOULD YOU HELP ME PLZ

stardobas
Posts: 3
Joined: Sat Nov 16, 2013 10:47 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by stardobas »

:? in wultiwii 2.3 I haven't success to upgrade SRF08... I've try but I can't compile stretch for my quadcopter....Please have you a stretch to give me for quadcopter just patched with applied sfr08 holding system? I've try to upgrade but.....no success...

stardobas
Posts: 3
Joined: Sat Nov 16, 2013 10:47 am

specification

Post by stardobas »

I've changed address in sensor stretch and now I see led blinking for ping sending....

NEWSSS:
using this: alt.EstAlt = (alt.EstAlt * 6 + sonarAlt * 2) >> 3;
I get only sonar value on altidute in the gui....and fine...work well....but I want use barometer altitude when go up 2 or 3 metres...
I wrote this:


alt.EstAlt = (alt.EstAlt * 6 + sonarAlt * 2) >> 3; // additional LPF to reduce baro noise (faster by 30 µs)
if (sonarAlt > 1) {
alt.EstAlt = (alt.EstAlt * 6 + BaroAlt * 2) >> 3;
}

but I continue to read only sonar value....never use barometer value....

Please HELPPPPPP!!

Mis
Posts: 203
Joined: Fri Apr 01, 2011 12:23 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Mis »

My idea of SONAR+BARO fusion:

Code: Select all

  #if(SONAR)              // BARO+SONAR Fusion
    if(sonarAlt > 0 && f.SMALL_ANGLES_25) {      // use sonar only if valid sonar data, and with inclinations below 25 degres
      float ratio = (SONAR_BARO_FUSION_HC-sonarAlt)/(SONAR_BARO_FUSION_HC-SONAR_BARO_FUSION_LC);  // baro/sonar ratio
      ratio = constrain(ratio, 0.0f, 0.90f);                // min sonar ratio = 0, max sonar ratio = 0.9
      BaroAlt = BaroAlt * (1.0f-ratio) + sonarAlt * ratio;
    }
  #endif
  alt.EstAlt = (alt.EstAlt * 6 + BaroAlt * 2) >> 3; // additional LPF to reduce baro noise (faster by 30 µs)

Need declaration for one "float scale;" variable at begin of "etEstimatedAttitude" function.
Then on config.h we need two more decalrations:
#define SONAR_BARO_FUSION_LC 100 // bellow 100cm use only sonar
#define SONAR_BARO_FUSION_HC 500 // above 500cm use only baro
That's all. Bettwen 1 and 5m althold use baro+sonar fusion proportional to sonar height (lower -> more sonar usage), below 1m only sonar is used, and above 5m only baro is used.
Additionally sonar is used only if inclination of copter is lower than 25deg, because in higher inclinations reading of sonar can have too high error.

stardobas
Posts: 3
Joined: Sat Nov 16, 2013 10:47 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by stardobas »

Wow...I've solve it but I don't considerate the inclination...perfect!!! I will try it!

User avatar
Crashpilot1000
Posts: 631
Joined: Tue Apr 03, 2012 7:38 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by Crashpilot1000 »

Oh, well what was f** up shit from the beginning to the end. Remember what a sonar can physically do and look at that code - it makes you cry.
That "fusion" is gross sh't. Remember: Sonar gives you RELATIVE distance - never absolute hight. So wait another 2 years until mwii understands that.

weebly
Posts: 13
Joined: Thu Feb 20, 2014 3:33 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by weebly »

I'm using multiwii 2.0. I tried to edit the code as described. But it doesn't work. Can someone please upload the full edited code. Plz plzz...... I need the full code. :( :( :( :(

bc power
Posts: 9
Joined: Thu May 08, 2014 9:59 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by bc power »

Guys I need to connect 4 srf02 modules for obstacle avoiding...please help me...

bc power
Posts: 9
Joined: Thu May 08, 2014 9:59 am

Re: Integration of SRF08 I2C sonar sensor (done)

Post by bc power »

I need an algorithm for srf02 4 modules....help me guys................................:)

iDaniel
Posts: 11
Joined: Mon Dec 15, 2014 9:51 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by iDaniel »

Hi
i´ve connected an SRF08 Module to my arduino uno. Also i´ve got an GY-521 i2c ACC connected. In the Gui is can see the sonar value aon debug3 and it works quite well,
until i dont turn on my transmitter, wich connected normal (no PPM SUM). Then it shows an i2c error and the sonar doesn´t work...but the ACC ist still working. I turn the transmitter of and the Sonar ist working again...

any ideas?

iDaniel
Posts: 11
Joined: Mon Dec 15, 2014 9:51 pm

Re: Integration of SRF08 I2C sonar sensor (done)

Post by iDaniel »

Ok i have tested now the same code, same frsky receiver, same sensor but another arduino(pro mini) and GY-88 Sensorboard. I works without i2c errors ... so i don´t know why, because of the other arduino or the sensorboard... but i did not want to use the uno anyway on my copter. So i won´t figure out why anymore :D

Post Reply