Skip to content

Commit eb988ef

Browse files
authored
Merge pull request #1965 from GauravKumar9920/1944-testing
added autoparking_v2 exercise
2 parents bf1c764 + 6a9403d commit eb988ef

File tree

8 files changed

+155
-3
lines changed

8 files changed

+155
-3
lines changed

db.sqlite3

0 Bytes
Binary file not shown.
337 KB
Loading
337 KB
Loading

exercises/static/exercises/autoparking_v2/web-template/launch/autoparking.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This launch file loads the world and models for the autoparking_v2 exercise.
1919

2020

2121
<include file="$(find gazebo_ros)/launch/empty_world.launch">
22-
<arg name="world_name" value="/RoboticsAcademy/exercises/autoparking_v2/web-template/autoparking.world"/>
22+
<arg name="world_name" value="/RoboticsAcademy/exercises/static/exercises/autoparking_v2/web-template/autoparking.world"/>
2323
<arg name="debug" value="$(arg debug)" />
2424
<arg name="gui" value="$(arg gui)" />
2525
<arg name="paused" value="$(arg paused)"/>

scripts/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export GAZEBO_RESOURCE_PATH=$GAZEBO_RESOURCE_PATH:$EXERCISES_STATIC_FILES/global
1515
export GAZEBO_RESOURCE_PATH=$GAZEBO_RESOURCE_PATH:$EXERCISES_STATIC_FILES/car_junction/web-template/
1616
export GAZEBO_RESOURCE_PATH=$GAZEBO_RESOURCE_PATH:$EXERCISES_STATIC_FILES/opticalflow_teleop/web-template/launch/
1717
export GAZEBO_RESOURCE_PATH=$GAZEBO_RESOURCE_PATH:$EXERCISES_STATIC_FILES/autoparking/web-template/launch/
18+
export GAZEBO_RESOURCE_PATH=$GAZEBO_RESOURCE_PATH:$EXERCISES_STATIC_FILES/autoparking_v2/web-template/launch/
1819
export GAZEBO_RESOURCE_PATH=$GAZEBO_RESOURCE_PATH:$EXERCISES_STATIC_FILES/montecarlo_visual_loc/web-template/launch/
1920
export GAZEBO_RESOURCE_PATH=$GAZEBO_RESOURCE_PATH:/usr/share/gazebo-11:/RoboticsAcademy/exercises/follow_line/web-template/launch/:/RoboticsAcademy/exercises/obstacle_avoidance/web-template/launch/:/RoboticsAcademy/exercises/vacuum_cleaner/web-template/launch/:/RoboticsAcademy/exercises/vacuum_cleaner_loc/web-template/launch/:/RoboticsAcademy/exercises/3d_reconstruction/web-template/launch/:/RoboticsAcademy/exercises/global_navigation/web-template/launch/:/RoboticsAcademy/exercises/car_junction/web-template/:/RoboticsAcademy/exercises/opticalflow_teleop/web-template/launch/:/RoboticsAcademy/exercises/autoparking/web-template/:/RoboticsAcademy/exercises/autoparking_v2/web-template/:/RoboticsAcademy/exercises/montecarlo_visual_loc/web-template/launch/
2021
export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/PX4-Autopilot/build/px4_sitl_default/build_gazebo:/catkin_ws/devel/lib

scripts/instructions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@
129129
},
130130
"autoparking_v2": {
131131
"gazebo_path": "/RoboticsAcademy/exercises/autoparking_v2/web-template/launch",
132-
"instructions_ros": ["/opt/ros/noetic/bin/roslaunch ./RoboticsAcademy/exercises/autoparking_v2/web-template/launch/autoparking.launch"],
133-
"instructions_host": "python3 /RoboticsAcademy/exercises/autoparking_v2/web-template/exercise.py 0.0.0.0"
132+
"instructions_ros": ["/opt/ros/noetic/bin/roslaunch ./RoboticsAcademy/exercises/static/exercises/autoparking_v2/web-template/launch/autoparking.launch"],
133+
"instructions_host": "python3 /RoboticsAcademy/exercises/static/exercises/autoparking_v2/web-template/exercise.py 0.0.0.0"
134134
},
135135
"montecarlo_visual_loc": {
136136
"gazebo_path": "/RoboticsAcademy/exercises/static/exercises/montecarlo_visual_loc/web-template/launch",
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Retreive the canvas elements and context
2+
var mapCanvas = document.getElementById("local-map-lasers"),
3+
ctx = mapCanvas.getContext("2d");
4+
5+
function paintEvent(car, obs, avg, lasers, ranges){
6+
ctx.clearRect(0, 0, mapCanvas.width, mapCanvas.height);
7+
8+
// Draw Car
9+
drawCar();
10+
11+
// Draw Laser
12+
drawLaser(lasers[0], ranges[0], "f", "#FF0000");
13+
drawLaser(lasers[1], ranges[1], "r", "#F7FF00");
14+
drawLaser(lasers[2], ranges[2], "b", "#0FFF00");
15+
}
16+
17+
function drawCar(){
18+
carWidth = 40;
19+
carHeight = 95;
20+
tiresize = carWidth / 5;
21+
22+
ctx.beginPath();
23+
24+
// Chassis
25+
ctx.fillStyle = 'black';
26+
ctx.fillRect(mapCanvas.width/2 - carWidth/2, mapCanvas.height/2 - carHeight/2, carWidth, carHeight);
27+
28+
ctx.stroke();
29+
30+
ctx.closePath();
31+
}
32+
33+
function drawLaser(laser, max_range, pos, color){
34+
let originx = 0;
35+
let originy = 0;
36+
let resizeFactor = 0.8;
37+
ctx.strokeStyle = color;
38+
switch(pos) {
39+
case "f":
40+
originx = mapCanvas.width/2;
41+
originy = mapCanvas.height/2 - carHeight/2 + 16;
42+
break;
43+
case "r":
44+
originx = mapCanvas.width/2 + carWidth/2;
45+
originy = mapCanvas.height/2;
46+
break;
47+
case "b":
48+
originx = mapCanvas.width/2;
49+
originy = mapCanvas.height/2 + carHeight/2;
50+
break;
51+
}
52+
53+
// Resizes the lasers
54+
max_range *= resizeFactor;
55+
56+
for (let d of laser){
57+
d[0] *= resizeFactor;
58+
59+
if (d[0] > max_range){
60+
py = originy - max_range * Math.sin(d[1]);
61+
px = originx + max_range * Math.cos(d[1]);
62+
}
63+
else{
64+
py = originy - d[0] * Math.sin(d[1]);
65+
px = originx + d[0] * Math.cos(d[1]);
66+
}
67+
// Rotates for right and back lasers
68+
let rotatedPoints;
69+
switch(pos) {
70+
case "f":
71+
72+
break;
73+
case "r":
74+
rotatedPoints = rotate(originx, originy, px, py, -90)
75+
px = rotatedPoints[0];
76+
py = rotatedPoints[1];
77+
break;
78+
case "b":
79+
rotatedPoints = rotate(originx, originy, px, py, 180)
80+
px = rotatedPoints[0];
81+
py = rotatedPoints[1];
82+
break;
83+
}
84+
85+
ctx.beginPath();
86+
ctx.moveTo(originx, originy);
87+
ctx.lineTo(px, py);
88+
ctx.stroke();
89+
90+
ctx.closePath();
91+
}
92+
}
93+
94+
// Rotates the point
95+
function rotate(cx, cy, x, y, angle) {
96+
let radians = (Math.PI / 180) * angle;
97+
let cos = Math.cos(radians);
98+
let sin = Math.sin(radians);
99+
let nx = (cos * (x - cx)) + (sin * (y - cy)) + cx;
100+
let ny = (cos * (y - cy)) - (sin * (x - cx)) + cy;
101+
return [nx, ny];
102+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// To decode the image string we will receive from server
2+
function decode_utf8(s){
3+
return decodeURIComponent(escape(s))
4+
}
5+
6+
// Websocket and other variables for image display
7+
var websocket_gui, operation, data;
8+
var map_data;
9+
10+
function declare_gui(websocket_address){
11+
websocket_gui = new WebSocket(websocket_address);
12+
13+
websocket_gui.onopen = function(event){
14+
connectionUpdate({connection: 'exercise', command: 'launch_level', level: '6'}, '*');
15+
if (websocket_code.readyState == 1) {
16+
alert("[open] Connection established!");
17+
connectionUpdate({connection: 'exercise', command: 'up'}, '*');
18+
}
19+
}
20+
21+
websocket_gui.onclose = function(event){
22+
connectionUpdate({connection: 'exercise', command: 'down'}, '*');
23+
if(event.wasClean){
24+
alert(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
25+
}
26+
else{
27+
alert("[close] Connection closed!");
28+
}
29+
}
30+
31+
// What to do when a message from server is received
32+
websocket_gui.onmessage = function(event){
33+
operation = event.data.substring(0, 4);
34+
if(operation == "#gui"){
35+
// Parse the entire Object
36+
data = JSON.parse(event.data.substring(4, ));
37+
38+
// Parse the Map data
39+
map_data = JSON.parse(data.map);
40+
paintEvent(map_data.car, map_data.obstacle, map_data.average, map_data.lasers, map_data.ranges);
41+
42+
// Send the Acknowledgement Message
43+
websocket_gui.send("#ack");
44+
}
45+
46+
};
47+
}
48+
49+
var canvas = document.getElementById("gui_canvas");

0 commit comments

Comments
 (0)