2009年2月27日星期五

summary and plan

Summary in recent two weeks
1.model for the DVL
2.tranfer PF algorithm from Matlab program to C code.
3.Integrate the computer sampling program[subsea program] (sensor data and AI/DA/DI/DO) in QNX OS.

plan in future two weeks
1.combination test(surface program and subsea program)
2.analyze and optimize the PF algorithm and make it can be applied in real time program
3.analyze the character of system according to the middle report of my phd stage.


underwater experiment(stage 6)<-assemble the control system of IAUV on electric cabin(stage 5)<-combination program test on land(stage 4)<-PF realtime demonstration(stage 3)->offline demonstration based on experiment data(stage 2)<-simulation patch demontration(stage 1).


currently, I am in the position of stage 1.
for my phd dissertation I need work to stage 3 as a base.If I can reach the stage 6,it means a excellent phd work.

Embed C program has been upload my website







OS: QNX 4.25
mainboard:SCM7026,
extend card ADT300,ADT680,Device Driver Card(self-research)
sensor: MTi, TCM2.5

function:
Read MTi,TCM2.5
AI/DA DO operation on ADT680

DA DO operation on ADT300

website:http://sites.google.com/site/qiangliresearch/qiang-li-s-homepage/uvmsprj

2009年2月25日星期三



Simulation scheme in Matlab/Simulink



Background: A vehicle(IMU and camera are mounted) is moving along a circle trajectory. the purpose is estimating the target position and vehicle's position simultaneouly.the red star is the feature point, the black line is the vehicle's trajectory. The experiment can demonstrate the PF(Particle Filter) can provide accurate target position and vehicle's position although the sensor only provide the unlimited bias data and UKF(Unscented Kalman Filter) is invalid.


In the figure, the 40seconds PF simulation is finished in 563 second,which shows the C program can not be utilized in real time estimation. It is the next step task.
And the other tasks include analyzing the problem in simulation and its stochastic character.

2009年2月22日星期日

C Mex files development and debug

development enviornment

/*
the matlab program are transfered to C files successfully. " that is *.m->*.c "
c mex are implemented with efficiency more 50 times more than matlab program

the development enviornment:
VC 6.0
Matlab 7.1

As a matter of fact, this is not a good development envoirnment assemble. Because the many function and toolbox can not be run under the enviornment. But they are on my hand.

the popular version are VC2005+matlab 2007b
*/

debug enviornment

/*
furthermore some techniques are need in debugging the C-mex function.
The following is the description of debug method. Although it is written
according to VC7.1, the test result of mine shows that it is usable under
VC6.0 enviornment


1.Start Microsoft Visual Studio Version 7.1 by typing at the DOS prompt
msdev filename.mexw32


2.In the Microsoft environment, from the Project menu, select Settings. In the window that opens, select the Debug tab. This options window contains edit boxes. In the edit box labeled Executable for debug session, enter the full path to where MATLAB resides. All other edit boxes should be empty.

3.Open the source files and set a break point on the desired line of code by right-clicking with your mouse on the line of code.

4.From the Build menu, select Debug, and click Go.

5.You will now be able to run your MEX-file in MATLAB and use the Microsoft debugging environment. For more information on how to debug in the Microsoft environment, see the Microsoft Development Studio or Microsoft Visual Studio documentation.

*/

2009年2月18日星期三

Progress in algorithm optimization

In particle fiter,the most time-cost program is large loop if the particle is large enough. In my program, I met the same problem.15000 particles are selected to describe the 24 state variable.

In order to test whether the C programe can improve the running efficiency I used a similar and simple C program to instead large loop part in Particle Filter. The result is pleased with me.

The first step I run 20s vehicle kinematic simulation and measure its output(noise are added). With these data I expected to estimate the optimal state during the 20s simulation. The result is estimation time spent on the cost large loop is 140s and 6 times longer than the realtime simulation. This is a large progress in the direction of forward to the real time state estimation. If the complete matlab code is used, the state estimation will cost 100minutes with the same measurement data in the previous state estimation.

The efficiency is improved 50 times.

2009年2月17日星期二

Matlab program optimazation

The research work today is analyzing why the PF algorithm run slowly in matlab environment? Can the efficiency be improved by optimalize the code of Matlab?
The simple and same test program are run in matlab and VC6.0.I expect to get the conclusion that whether it is feasible to modify and optimize the current matlab code to improve the efficiency in order to make it can be run realtime in PC.




Case I research
In VC6.0, the program code is like this
// timetest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include
#include

int main(int argc, char* argv[])
{
DWORD Begin;
DWORD Gap;
long i,j,sum;
sum = 0;
Begin = GetTickCount();
for(i=0;i<1000001;i++)
{
for(j=0;j<21;j++)
{
sum = sum + 1;
}
}

Gap1 = GetTickCount() - Begin;
cout<< Gap1 < return 0;
}
Run the program and the elapsed time is 63ms
But if it is run in matlab, the code is like
tic;
sum = 0;
for i = 1:1000000
for j = 1:20
sum = sum * 1;
end
end
t = toc
fprintf('cost time is %d\n',t);

the running result is cost time is 26 s

so we can see
(1) the efficiency can be improved greatly, if the code is rewritten in C program.
(2) When we write Matlab program and have to use the nested loop, the time of outside loop use a small value can improve the running efficiency.


Case II
mcc method case I:
1. Using mcc –m myfun.m to produce the executive file myfun.
Case and efficiency analysis
//C function manually
#include "stdafx.h"
#include
#include

int main(int argc, char* argv[])
{
DWORD Begin;
DWORD Gap;
long i,j,sum;
sum = 0;
Begin = GetTickCount();
for(j=0;j<6;j++)
{
for(i=0;i<100000001;i++)
{
sum = sum + 1;
}
}
Gap = GetTickCount() - Begin;
cout< return 0;
}

Time spent in the C program manually is 1.5s
//mcc –m messay.m
function sum=messay()
tic;
sum = 0;
for j = 1:5
for i =1:1:100000000
sum = sum + 1;
end
end
tt = toc;
%messayfun(sum,tt);
fprintf('sum is %f,%d\n',sum,tt);

Time spent in the program is 5.01s

mcc method case II:

test3.m
function test3()
tic;
sum = 0;
for i = 1:10
for j = 1:1000000
sum = 2+1;
end
end
tt = toc;
fprintf('time cost test3 is %d\n',tt);


run time is 60.9ms

test3.m
(script file)
tic;
sum = 0;
for i = 1:10
for j = 1:1000000
sum = 2+1;
end
end
tt = toc;
fprintf('time cost test3 is %d\n',tt);


run time is 11s
From the the above result, we can make a conclusion that function can run faster than the script file.


test2.m
tic;
for i = 1:10
d = feval('messayfun',2,3);
end
tt = toc;
fprintf('time cost is %d\n',tt);

messayfun.m
function c = messayfun(a,b)
for j=1:1000000
c = a+b;
end
time cost is 61.4ms


#include "stdafx.h"
#include
#include

int main(int argc, char* argv[])
{
DWORD Begin;
DWORD Gap;
long i,j,sum;
sum = 0;
Begin = GetTickCount();
for(j=0;j<11;j++)
{
for(i=0;i<1000001;i++)
{
sum = sum + 1;
}
}
Gap = GetTickCount() - Begin;
cout< return 0;
}

time cost 31ms

It can be seen that the time cost with C program can be decreased 50%.

Conclusion:
1. “feval” function’s efficiency is high.
2. The most efficient method is C program and it need to be written to replace the loop part in matlab program. The efficiency can be increased to twice.


Currenly, Matlab program optimality method is very good.The efficiency can be increased to twice if the C code program is used. It’s impossible to expect the program efficiency increase more 300 times(in order to run the algorithm realtime) only depended on transferring matlab program to C program. The feasible method is decreasing the particle number, decrease the state variable, or modify the PF method.

2009年2月16日星期一

work in a future weeks

for three days, I have made some initial result in low level data sampling based on QNX.
(1) find the extended 4 serial port
(2) ADT300 DA , DI/O, ADT680 DA,AD,DI/O

next step I need optimalize PF (pariticle filter)algorithm, it has been a big obtacle if I want to estimate the static error mean of IMU, demonstrate estimation algorithm robustness. Futhermore the optimaliztion work also is important for the ultimate realtime estimation.

"boost" + "Baysian++" is the best realtime realization schedule, but it needs me
(1)to transfer the matlab program into C++
(2)to be familiar with MSVC 8.0, Baysian ++ and boost
It is a large deal of work.


For the first step I need analyze the advantage of PF in my special problem, so the first step I want to analyze why the PF algorithm is slow implemented in Matlab environment and propose some improvement to improve its run efficiency.

the second, the boost and baysian ++ schedule will be applied in my system.

I expect to finish this works in two weeks.

God save me!

2009年2月14日星期六

Test ADT300 & ADT680

experiment system
Today I am sucessful in test ADT300 to output analog voltage and Digital bit, but fail to test ADT680. It's my job tomorrow.
the three card are used in our system(SCM7026,ADT300 and ADT680)




1.when using function inp(),outp(), we have to use -T1 optition when the program is compiled and linked based on QNX.
2.Although PC104 is compact and convinent in embeded system, it is difficult to mount and dismount.
3.It's my first time to read adc value and write dac value by address operation.

Saint Valentine's Day

Today is Valentine's Day. No rose and chocolate.
But we have happiness and harmonious loveness between my sweet heart and me.

I love you. Ping.!

Kiss!

2009年2月13日星期五

who can help me on QNX

hi,
I am using Qnx4.25 on SCM 7026(a motherboard produced by shengbo in China). The motherboard can provide 6 serial port. Port 1,2 are original and the port 3-6 are extended port.

I have found the extended port(3-6) use the shared interrupt number 11 So I write the following sentenses to start the extended port in file--/etc/config/sysinit.1
/bin/Dev.ser -N/dev/ser3 D000,11 &
/bin/Dev.ser -N/dev/ser4 D008,11 &
/bin/Dev.ser -N/dev/ser5 D010,11 &
/bin/Dev.ser -N/dev/ser6 D018,11 &
but the system is crashed. when I load one port, such as only one sentence
/bin/Dev.ser -N/dev/ser3 D000,11 &
the serial port 3 can work well. who can tell me why?

thanks...

2009年2月11日星期三

DVL test at pool in S.I.A

Last afternoon, I tested the DVL at pool in SIA. The test time was from 16:37 to 21:21. Thanks for help from Dr.Qifeng Zhang and Mr Xinke Zhu.
Today the data will be processed and the error model of DVL will be obtained.





2009年2月10日星期二

Test DVL produced by RDI Co.


Workhorse Navigator Doppler Velocity Log
According to the suggest in the operation manual, I sink the DVL into water in a bucket, and the DVL touched with the bottom of bucket.
I spent the whole afternoon on sampling the data from DVL. But I failed. I guess the reason is the distance between DVL and bottom is too little. Tomorrow I will put the DVL in the pool(depth is 9 meters) and test the DVL again.
Good luck for me.
BTW: today I found the Octans in the storehouse of laboratory. I have opptunity to make the error model for the two important underwater sensor.

2009年2月4日星期三

New challenge in new year

the Spring Festival will be end,I will be back to shenyang soon. Whether I can realize my dream, it depends on. Can offer comes to me, I expected ......

It's the important factors.

God bless me and my sweet heart.

2009年2月1日星期日

Zhangyu wine museum

sweet heart



trapdoor in 1865