Last active
September 6, 2020 16:42
-
-
Save lukicdarkoo/2d2513b74a370a693ae643975f34dc4d to your computer and use it in GitHub Desktop.
Log Webots position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#VRML_SIM R2020b utf8 | |
WorldInfo { | |
info [ | |
"The model of the e-puck 2 robot" | |
] | |
title "e-puck simulation" | |
coordinateSystem "NUE" | |
} | |
Viewpoint { | |
orientation 0.04913069345659068 0.9922428678493876 0.11419398479121845 3.8679 | |
position -0.22134442152396674 0.09258687079617126 -0.19815687940397006 | |
follow "e-puck2" | |
} | |
TexturedBackground { | |
} | |
TexturedBackgroundLight { | |
} | |
RectangleArena { | |
floorSize 2 2 | |
} | |
WoodenBox { | |
translation -0.2 0.05 0.683174 | |
rotation 0 1 0 0.5 | |
size 0.1 0.1 0.1 | |
} | |
WoodenBox { | |
translation -0.75 0.05 -0.35 | |
rotation 0 1 0 4.96782 | |
name "wooden box(1)" | |
size 0.1 0.1 0.1 | |
} | |
WoodenBox { | |
translation 0.5 0.05 0.35471 | |
rotation 0 1 0 5.36782 | |
name "wooden box(2)" | |
size 0.1 0.1 0.1 | |
} | |
WoodenBox { | |
translation -0.3 0.05 -0.36 | |
rotation 0 1 0 5.36782 | |
name "wooden box(3)" | |
size 0.1 0.1 0.1 | |
} | |
WoodenBox { | |
translation -0.65 0.05 0.66 | |
rotation 0 1 0 5.36782 | |
name "wooden box(4)" | |
size 0.1 0.1 0.1 | |
} | |
E-puck { | |
translation -0.04633846669838243 -5.5929604977326616e-05 -4.043778093383073e-05 | |
rotation 0.0008774908405972536 0.9999992265351687 -0.0008814413700977869 1.570339375877006 | |
name "e-puck2" | |
controller "gps_logger" | |
version "2" | |
camera_width 160 | |
camera_height 120 | |
turretSlot [ | |
# Important! GPS is added to the turret slot! | |
GPS { | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pathlib import Path | |
import matplotlib.pyplot as plt | |
from controller import Robot | |
# Change this! Path to plot. | |
PLOT_FILENAME = os.path.join(str(Path.home()), 'Pictures', 'plot.pdf') | |
robot = Robot() | |
timestep = int(robot.getBasicTimeStep()) | |
# Enable motors to move the robot in a circle | |
left_motor = robot.getMotor('left wheel motor') | |
right_motor = robot.getMotor('right wheel motor') | |
left_motor.setPosition(float('inf')) | |
right_motor.setPosition(float('inf')) | |
left_motor.setVelocity(0.1) | |
right_motor.setVelocity(0.5) | |
# Enable GPS | |
gps = robot.getGPS('gps') | |
gps.enable(timestep) | |
# Sample robot's location | |
xs = [] | |
ys = [] | |
while robot.step(timestep) != -1: | |
# By default, Webots use NUE coordinate system. | |
# This can be changed in `WorldInfo` to ENU system. | |
# See: https://github.com/cyberbotics/webots/pull/1643 | |
# However, here we do conversion for GPS only. | |
x = - gps.getValues()[2] | |
y = gps.getValues()[0] | |
xs.append(x) | |
ys.append(y) | |
# Make and save the plot | |
plt.plot(xs, ys) | |
plt.savefig(PLOT_FILENAME) | |
print(f'The plot is saved to {PLOT_FILENAME}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment