Hot to change speed to distance?

Hello,
I have array date with time and speeds taken from left and right wheel and I want to calculate distance in simulink. How to do that?
That is my code:
It takes speeds [RPM] from Roboteq Telemetry and adds time from MATLAB Function. 40 [cm] is circumference of a wheels and 75 is gear ratio. So on the output I have now speed [cm/min]. I know that I have to multiply it times time in minutes, but I don't know how.
That how it looks like in workspace:
Minus means that wheel spins backwards so it doesn't matter. Kolums 1-6 is time (year, month, day, hour, minute, second), 7 is left wheel speed and 8 is right wheel speed.

6 Comments

What are the units of speed?
How do you intend to account for different left/right wheel speeds?
From roboteq telemetry unit of speed is revolutions per minute. But when I multiply it times wheel circumference (40 cm) I have centimeters per minute.
I have samples time so I think that the easiest way is to count difference between time of current sample and time of sample before. Then I can change that counted time to minutes and multiply that time (in minutes) times speeds (separately left and right wheel). Then I could create another 2 columns with distance.
And the problem is that I don't know how to take time from previous sample. Maybe I have to create another Matlab function to do that?
You could have a look at datenum() and associated functions. It should help you achieve what you want.
The difference between datetime objects is a duration object that you can use minutes() or seconds() on to extract the time in appropriate units.
>> input=rand(1,1000); % Input Training data
>> output= (input>0.5); % Output Training data (returns 1 if input is greater than 0.5)
>> net=patternnet(1) % Create a neural network with 1 hidden layer of with 1 neuron
% patternnet([5 10]) would create 2 hidden layers with 5 and 10 neurons …
>> net=train(net, input, output); % Train neural network
>> net(0.3) % test neural network (close training UI if it opens)
>> net(0.6)
load groupA&B.mat
>> [idx,C]=kmeans(lTFaces',10);
>> hFaces=U(:,1:20)*C';
>> imagesc(reshape(hFaces(:,4),[100 100]))

Sign in to comment.

Answers (1)

plaziok
plaziok on 4 Aug 2017
Edited: plaziok on 4 Aug 2017
I think that I can use etime. https://www.mathworks.com/help/matlab/ref/etime.html
But I don't know how to write appropriate function in Matlab function block. Could somebody help me?
function e = fcn(t2,t1)
eml.extrinsic('etime');
eml.extrinsic('now');
t1 =
t2 =
e = etime(t2,t1)
end
I don't know how to define t1 and t2 to read elapsed time between next samples.
############
I have an another idea too. I can use this code:
function D = fcn(A)
eml.extrinsic('diff');
V = A(:,6)
D = diff(V)
end
Then I have a vector with seconds and diff calculates difference between successive values from the previous vector.
It works in command window but there are errors in simulation:
%

1 Comment

You are feeding the date/time information of length 6 together with 2 entries of gain to produce something of length 8. However that might be 8 x 1. Certainly you are not feeding in two dates.
Your problem description says you have times taken from the left and right wheel; it does not then make sense for you to use now() to generate times.
Remember, now() reflects the real-time of running the program, which is not necessarily much related to the simulation time. For example setting a simulation time to picoseconds does not cause Simulink to be able to actually run in picoseconds per iteration. And when you pause in the debugger, does it really make sense for some times to jump massively? You should seldom be reading now() in Simulink; simulation time is more relevant.

Sign in to comment.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products

Asked:

on 3 Aug 2017

Commented:

on 15 Oct 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!