-
Notifications
You must be signed in to change notification settings - Fork 4
/
get_encoder.m
32 lines (24 loc) · 1.02 KB
/
get_encoder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [l_tick, r_tick] = get_encoder()
%Function which returns encoder movement in ticks
global vrep;
global clientID;
global left_wheel_h;
global right_wheel_h;
global leftMotorPreviousAngle;
global rightMotorPreviousAngle;
global leftRotation;
global rightRotation;
global ticks_per_rev;
%Determine how much radians per each pulse need to walk
RPP = (2*pi) / ticks_per_rev;
[~, anglel] = vrep.simxGetObjectOrientation(clientID, left_wheel_h, -1, vrep.simx_opmode_buffer);
leftGama = anglel(3);
leftRotation = leftRotation + getAngleDiff(leftGama, leftMotorPreviousAngle);
leftMotorPreviousAngle = leftGama;
l_tick = floor(leftRotation / RPP);
[~, angler] = vrep.simxGetObjectOrientation(clientID, right_wheel_h, -1, vrep.simx_opmode_buffer);
rightGama = angler(3);
rightRotation = rightRotation + getAngleDiff(rightGama, rightMotorPreviousAngle);
rightMotorPreviousAngle = rightGama;
r_tick = floor(rightRotation / RPP);
end