root / branches / 16299_s10 / matlab / motionModel.m @ 1810
History | View | Annotate | Download (1016 Bytes)
1 | 1712 | bbland | function [x, y, theta, r, phi, state] = motionModel(v,omega,xold,yold,thetaold,dt,state) |
---|---|---|---|
2 | 1708 | bneuman | |
3 | 1713 | bneuman | [numRobots,z] = size(v); |
4 | 1708 | bneuman | |
5 | 1795 | cbrownel | wheelMax = [100; 100]; |
6 | wheelMin = [-100; -100]; |
||
7 | |||
8 | R = 2.5; |
||
9 | L = 12; |
||
10 | 1810 | cbrownel | noise = .5; |
11 | 1795 | cbrownel | |
12 | transform = [ R/2 R/2; -R/L R/L]; |
||
13 | inverseTransform = inv(transform); |
||
14 | |||
15 | 1810 | cbrownel | //Transforms from v, omega into wheel speed, limits wheel speed and adds noise, then translates back. |
16 | 1795 | cbrownel | for i=1:numRobots, |
17 | |||
18 | 1802 | bneuman | wheels = inverseTransform * [v(i); omega(i)]; |
19 | 1810 | cbrownel | wheels = min(wheels, wheelMax) + noise * (rand - .5); |
20 | wheels = max(wheels, wheelMin) + noise * (rand - .5); |
||
21 | 1797 | bneuman | q = transform * wheels; |
22 | 1795 | cbrownel | v(i) = q(1); |
23 | omega(i) = q(2); |
||
24 | |||
25 | end |
||
26 | |||
27 | |||
28 | 1712 | bbland | x = zeros(numRobots,1); |
29 | y = zeros(numRobots,1); |
||
30 | theta = zeros(numRobots,1); |
||
31 | r = zeros(numRobots,1); |
||
32 | phi = zeros(numRobots,1); |
||
33 | |||
34 | for i=1:numRobots, |
||
35 | |||
36 | x(i) = xold(i) + cos(thetaold(i))*v(i)*dt; |
||
37 | y(i) = yold(i) + sin(thetaold(i))*v(i)*dt; |
||
38 | theta(i) = thetaold(i) + omega(i)*dt; |
||
39 | |||
40 | r(i) = sqrt((x(i)-x(1))^2 + (y(i)-y(1))^2); |
||
41 | 1713 | bneuman | phi(i) = theta(1) - atan2(y(i)-y(1), x(i)-x(1)); |
42 | 1712 | bbland | |
43 | 1708 | bneuman | end |
44 | 1712 | bbland | |
45 | end |