Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
a40f232
Initial commit
dj4park Dec 23, 2020
371ef57
Initial Webots simulation.
dj4park Dec 23, 2020
b159082
Added Autonomous Mode and Manual Mode Controllers
dj4park Dec 24, 2020
ca41705
Switch statement to choose controller
dj4park Dec 24, 2020
5bbb1c5
reformat code and added keyboard
dj4park Dec 24, 2020
70bf158
World file
dj4park Dec 24, 2020
54cabc8
Updating .gitignore
dj4park Dec 29, 2020
ae36eb2
Added IMU (Gyroscope) sensor
dj4park Dec 29, 2020
c0c75ba
Added IMU (Accelerometer) sensor
dj4park Dec 29, 2020
857f32f
Reformatting Initializer code
dj4park Dec 29, 2020
90d5997
Changes made to the world.
dj4park Dec 29, 2020
5bcdc1c
Delete Initialize.asv
dj4park Dec 29, 2020
5299fef
Deleted GPS sensor
dj4park Dec 29, 2020
583c68e
Sensor specifications can now be customized through the Parameters.m …
dj4park Dec 29, 2020
2104392
IMU parameter settings
dj4park Dec 29, 2020
148ea46
Changed to R2021a
dj4park Dec 29, 2020
420bfb6
Encoder ticks to robot pose estimation
dj4park Dec 30, 2020
67062a0
Checking enc2pose with true robot pose
dj4park Dec 30, 2020
20b975a
Added units to parameter values
dj4park Dec 30, 2020
ba59d0a
Tracking the orientation of the robot
dj4park Dec 30, 2020
e5da1ee
Changes to the world
dj4park Dec 30, 2020
282dad3
Fixed wrong direction turning for the robot
dj4park Jan 1, 2021
4912f7c
Removed objects from table
dj4park Jan 1, 2021
3e119b4
Fixed wrong naming fot left and right motors
dj4park Jan 1, 2021
535d7b6
Minor fixed and changes to the code
dj4park Jan 1, 2021
e8f5109
Odometry using encoder values works
dj4park Jan 1, 2021
01062fa
Fixed odometry not tracking backwards movement
dj4park Jan 1, 2021
cb81083
Testing noise and resolution values for the encoder
dj4park Jan 1, 2021
e8fe855
Changed the data structure for the true robot position to align with …
dj4park Jan 1, 2021
c3be3c8
Updating autonomous mode and manual mode
dj4park Jan 1, 2021
fa8cb0b
Using IMU values to estimate the position
dj4park Jan 3, 2021
0e99233
Disableing matlab pop up
dj4park Jan 3, 2021
d6d0c8b
Getting IMU acceleration values and plotting velocity and distance
dj4park Jan 3, 2021
6837db0
Changed the time step to be smaller
dj4park Jan 3, 2021
9546cfa
Converting IMU data to pose estimation.
dj4park Jan 4, 2021
6a30b33
Changing encoder resolution to be default
dj4park Jan 6, 2021
5096377
Implementing kinematic model with encoders
dj4park Jan 6, 2021
2d57189
Added spaces
dj4park Jan 6, 2021
82dfd59
Fixed enc2wheelvel for odometry pose estimation using kinematic model
dj4park Jan 6, 2021
190fa28
Function name change
dj4park Jan 6, 2021
6cb1c08
Changed filename to main
dj4park Jan 6, 2021
092ff12
Changed back to first_controller because of Wevots :anguished:
dj4park Jan 6, 2021
9789665
Added the missing .m
dj4park Jan 6, 2021
95be4c9
Fixed velocity calculation from IMU acceleration
dj4park Jan 7, 2021
7813147
Kinematic model of differential drive that takes v and w as input
dj4park Jan 7, 2021
13615b2
Replaced inertial unit node to gyroscope node
dj4park Jan 7, 2021
5859e1c
Comments describing what the input U looks like
dj4park Jan 7, 2021
8032547
Manual & Autonomous mode now supports localization using encoders and…
dj4park Jan 7, 2021
1a7402d
Added compass node to complete the full IMU
dj4park Jan 7, 2021
2e9e59a
Deleted file.
dj4park Jan 7, 2021
5084a9d
Updated .gitignore
dj4park Jan 7, 2021
5a7f884
Setting the initial position and orientation of the robot
dj4park Jan 10, 2021
b688451
Using the InertialUnit node for the Magnetometer model.
dj4park Jan 10, 2021
9334990
Updating .gitignore and small changes
dj4park Jan 10, 2021
8b71626
Implementation of Kalman Filter taken from MTE 544
dj4park Jan 10, 2021
8a7038c
Setting up Kalman Filter for orientation estimation using Gyro and Ma…
dj4park Jan 10, 2021
8294410
World file update
dj4park Jan 10, 2021
bb0b036
Testing pose estimation with kalman filter for orientation
dj4park Jan 10, 2021
151e86f
World update
dj4park Jan 10, 2021
f63b48c
Added a compass plot to visualize the estimated orientation
dj4park Jan 10, 2021
9b4d529
Kalman filter for orientation estimation
dj4park Jan 11, 2021
6650c02
Empty initial commit
dj4park Jan 12, 2021
10e9c23
initial commit
dj4park Jan 13, 2021
edc5bf4
Resolved merge conflict
dj4park Jan 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

*.asv
simulation/worlds/.desk.wbproj
simulation/controllers/first_controller/test_plotting.m
simulation/controllers/first_controller/manual.mat
58 changes: 58 additions & 0 deletions simulation/controllers/first_controller/Initialize.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
wb_console_print(sprintf('Initializing...\n'), WB_STDOUT);

%% LEFT, RIGHT MOTORS
wb_console_print(sprintf('Checking Motors'), WB_STDOUT);
motor = [];
motor_names = [ "left_motor", "right_motor" ];
for i = 1:2
motor(i) = wb_robot_get_device(convertStringsToChars(motor_names(i)));
wb_motor_set_position(motor(i), inf);
wb_motor_set_velocity(motor(i), 0.0);
end
wb_console_print('DONE', WB_STDOUT);

%% LEFT, RIGHT ENCODERS
wb_console_print(sprintf('Checking Encoders'), WB_STDOUT);
ps = [];
ps_names = [ "left_ps", "right_ps" ];
for i = 1:2
ps(i) = wb_robot_get_device(convertStringsToChars(ps_names(i)));
wb_position_sensor_enable(ps(i), TIME_STEP);
end
wb_console_print('DONE', WB_STDOUT);

%% RANGE FINDER (TOF)
wb_console_print(sprintf('Checking TOF'), WB_STDOUT);
tof_name = "tof";
tof = wb_robot_get_device(convertStringsToChars(tof_name));
wb_range_finder_enable(tof, TIME_STEP);
wb_console_print('DONE', WB_STDOUT);

%% IMU
% GYRO
wb_console_print(sprintf('Checking IMU (Gyro)'), WB_STDOUT);
imu_gyro_name = "imu_gyro";
imu_gyro = wb_robot_get_device(convertStringsToChars(imu_gyro_name));
wb_gyro_enable(imu_gyro, TIME_STEP);
wb_console_print('DONE', WB_STDOUT);

% ACC
wb_console_print(sprintf('Checking IMU (Acc)'), WB_STDOUT);
imu_acc_name = "imu_acc";
imu_acc = wb_robot_get_device(convertStringsToChars(imu_acc_name));
wb_accelerometer_enable(imu_acc, TIME_STEP);
wb_console_print('DONE', WB_STDOUT);

% MAG
wb_console_print(sprintf('Checking IMU (Mag)'), WB_STDOUT);
imu_mag_name = "imu_mag";
imu_mag = wb_robot_get_device(convertStringsToChars(imu_mag_name));
wb_inertial_unit_enable(imu_mag, TIME_STEP);
wb_console_print('DONE', WB_STDOUT);

%% KEYBOARD INPUT
wb_console_print(sprintf('Checking Keyboard'), WB_STDOUT);
wb_keyboard_enable(TIME_STEP)
wb_console_print('DONE', WB_STDOUT);

wb_console_print(sprintf('Initialization Complete.\n'), WB_STDOUT);
116 changes: 116 additions & 0 deletions simulation/controllers/first_controller/Mode_Autonomous.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
% MAIN LOOP
wb_console_print('Starting Autonomous Mode!', WB_STDOUT);

%% INITIALIZATION
step = 1;
samples = 0;

% initial pose of the robot
position = wb_supervisor_field_get_sf_vec3f(trans_field);
orientation = wb_supervisor_field_get_sf_rotation(orien_field);
init_pose = [position(1) position(3) orientation(4)]'; % [x z theta]
true_pose(:, step) = init_pose;

% initializing values for encoder
pose_enc(:, step) = init_pose;
prev_enc_left = 0;
prev_enc_right = 0;

% initial position and velocity for IMU
pose_imu(:, step) = init_pose;
prev_imu_acc_z = 0;
prev_imu_vel_z = 0;

while wb_robot_step(TIME_STEP) ~= -1
step = step + 1;

% circular movement
left_speed = 1.0 * MAX_SPEED;
right_speed = 2.0 * MAX_SPEED;

for i=1:2
if i == 1
wb_motor_set_velocity(motor(i), left_speed);
end
if i == 2
wb_motor_set_velocity(motor(i), right_speed);
end
end

%% ENCODER TO POSE USING KINEMATIC MODEL
new_enc_left = wb_position_sensor_get_value(ps(1));
new_enc_right = wb_position_sensor_get_value(ps(2));

diff_enc_left = new_enc_left - prev_enc_left;
diff_enc_right = new_enc_right - prev_enc_right;

W = enc2wheelvel(diff_enc_left, diff_enc_right, TIME_STEP);
mu = kinematicModel(pose_enc(:, step-1), W, TIME_STEP, WHEEL_RADIUS, WHEEL_FROM_CENTER);

pose_enc(:, step) = mu;
prev_enc_left = new_enc_left;
prev_enc_right = new_enc_right;

%% TOF
image = wb_range_finder_get_range_image(tof);

%% IMU
% IMU, Gyro
roll_pitch_yaw_array = wb_gyro_get_values(imu_gyro);
new_imu_gyro_y = roll_pitch_yaw_array(2);

% IMU, Acce
x_y_z_array = wb_accelerometer_get_values(imu_acc);
new_imu_acc_z = x_y_z_array(3);

wb_console_print(sprintf('gyro: %g %g %g\n', roll_pitch_yaw_array(1), roll_pitch_yaw_array(2), roll_pitch_yaw_array(3)), WB_STDOUT);
wb_console_print(sprintf('acce: %g %g %g\n', x_y_z_array(1), x_y_z_array(2), x_y_z_array(3)), WB_STDOUT);

vel_z = imu_acc2vel(new_imu_acc_z, prev_imu_vel_z, TIME_STEP);

if abs(new_imu_gyro_y) < 0.001
new_imu_gyro_y = 0;
end

if abs(vel_z) < 0.001
vel_z = 0;
end

U = [vel_z new_imu_gyro_y]';

wb_console_print(sprintf('U: %g %g\n', U(1), U(2)), WB_STDOUT);

mu = kinematicModel_vw(pose_imu(:, step-1), U, TIME_STEP);

pose_imu(:, step) = mu;
prev_imu_acc_z = new_imu_acc_z;
prev_imu_vel_z = vel_z;

%% PLOTTING
% Getting true position
position = wb_supervisor_field_get_sf_vec3f(trans_field);
orientation = wb_supervisor_field_get_sf_rotation(orien_field);

true_pose(1, step) = position(1);
true_pose(2, step) = position(3);
true_pose(3, step) = orientation(4);

%% Plotting position of robot on a map (true, odometry)
figure(1)
plot(true_pose(1, step), -true_pose(2, step), 'ro');
hold on;
plot(pose_enc(1, step), -pose_enc(2, step), 'bx');
hold on;
plot(pose_imu(1, step), -pose_imu(2, step), 'g.');
hold on;
axis([-0.8 0.8 -0.6 0.6]);
rectangle('Position',[-TABLE_WIDTH/2 -TABLE_HEIGHT/2 TABLE_WIDTH TABLE_HEIGHT])
legend("True Position", "Odometry", "IMU Estimation");
hold off;

%% if your code plots some graphics, it needs to flushed like this:
drawnow;
end

%% CLEAN UP
% cleanup code goes here: write data to files, etc.
Loading