Skip to content

Commit

Permalink
Moved Python and C++ tutorials directory to root level
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Nov 25, 2024
1 parent e22cf59 commit a263ea7
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 7 deletions.
2 changes: 1 addition & 1 deletion definitions/jackal.vehicle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</chassis>

<!-- Motor controller -->
<controller class="twist_ideal" />
<controller class="twist_ideal" /> <!-- "twist_ideal" or "twist_pid" -->

</dynamics>

Expand Down
2 changes: 1 addition & 1 deletion docs/mvsim-cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ Command ``mvsim topic``
mvsim topic hz <topicName> Estimate topic publication rate (in Hz)
Can be used to list or inspect the publication of MVSim (not ROS!) topics with sensor and pose data.
These topics are accessible via the provided Python API, refer to examples: https://github.com/MRPT/mvsim/tree/develop/mvsim_tutorial/python
These topics are accessible via the provided Python API, refer to examples: https://github.com/MRPT/mvsim/tree/develop/examples_python
2 changes: 1 addition & 1 deletion docs/teleoperation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If no data is being published to ``/cmd_vel``, or if you run MVSim without ROS s
three alternative methods can be used to move the robots:

- Via ZMQ messages using the MVSim built-in messaging protocol (Write me!).
See a `Python code example <https://github.com/MRPT/mvsim/blob/develop/mvsim_tutorial/python/mvsim-teleop.py>`_.
See a `Python code example <https://github.com/MRPT/mvsim/blob/develop/examples_python/mvsim-teleop.py>`_.
- Joystick, if present (see below).
- Keyboard, from the MVSim GUI (see below).

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
125 changes: 125 additions & 0 deletions examples_python/plot-log-files-4-wheels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/env python3

# Usage:
# plot-log-files.py session1-mvsim_r1_logger_pose.log

# Requirements:
# pip install pandas matplotlib

import pandas as pd
import matplotlib.pyplot as plt
import sys
import os


def main(file_path):
# Read the main file
try:
main_data = pd.read_csv(file_path, skipinitialspace=True)
print(f"Main data loaded from {file_path}")
except Exception as e:
print(f"Error reading {file_path}: {e}")
return

# Define the wheel files based on the main file name
base_name = file_path.replace("pose.log", "")
wheel_files = [f"{base_name}wheel{i}.log" for i in range(1, 5)]

# Load wheel data
wheel_data = {}
for i, wheel_file in enumerate(wheel_files, start=1):
try:
wheel_data[i] = pd.read_csv(wheel_file, skipinitialspace=True)
print(f"Wheel {i} data loaded from {wheel_file}")
except Exception as e:
print(f"Error reading {wheel_file}: {e}")
return

# Create plots for the wheel files (non-blocking)
plot_wheel_data(wheel_data)

# Create plots for the main file (blocking)
plot_main_data(main_data)


def plot_main_data(data):
"""Create plots for the main file data."""
plt.figure(figsize=(12, 8))

# print(data.columns)
ts = data['Timestamp'].to_numpy()

# Plot 1: qx, qy, qz over time
plt.subplot(3, 1, 1)
plt.plot(ts, data['qx'].to_numpy(), label='qx')
plt.plot(ts, data['qy'].to_numpy(), label='qy')
plt.plot(ts, data['qz'].to_numpy(), label='qz')
plt.xlabel('Timestamp')
plt.ylabel('Position')
plt.title('Position (qx, qy, qz) vs Time')
plt.grid()
plt.legend()

# Plot 2: Orientation angles (qpitch, qroll, qyaw) over time
plt.subplot(3, 1, 2)
plt.plot(ts,
data['qpitch'].to_numpy(), label='qpitch')
plt.plot(ts,
data['qroll'].to_numpy(), label='qroll')
plt.plot(ts,
data['qyaw'].to_numpy(), label='qyaw')
plt.xlabel('Timestamp')
plt.ylabel('Orientation')
plt.title('Orientation Angles vs Time')
plt.grid()
plt.legend()

# Plot 3: dqz over time
plt.subplot(3, 1, 3)
plt.plot(ts, data['dqx'].to_numpy(), label='dqx', color='red')
plt.plot(ts, data['dqy'].to_numpy(), label='dqy', color='green')
plt.plot(ts, data['dqz'].to_numpy(), label='dqz', color='blue')
plt.xlabel('Timestamp')
plt.ylabel('Velocity')
plt.title('Velocity components')
plt.grid()
plt.legend()

plt.tight_layout()
plt.show()


def plot_wheel_data(wheel_data):
"""Create plots for the wheel data."""
plt.figure(figsize=(12, 12))

# Create one plot per variable group across all wheels
variables = ['friction_x', 'friction_y',
'velocity_x', 'velocity_y',
'torque', 'weight']
wheel_names = ['LR', 'RR', 'LF', 'RF']

for i, var in enumerate(variables, start=1):
plt.subplot(3, 2, i)
for wheel, data in wheel_data.items():
ts = data['Timestamp'].to_numpy()
plt.plot(ts,
data[var].to_numpy(), label=f'{wheel_names[wheel-1]} wheel')
plt.xlabel('Timestamp')
plt.ylabel(var)
plt.title(f'{var.capitalize()} vs Time')
plt.grid()
plt.legend()

plt.tight_layout()
plt.show(block=False)


if __name__ == "__main__":
# Check if the path to the main file is provided
if len(sys.argv) != 2:
print("Usage: python3 script.py </path/to/session1-mvsim_r1_logger_pose.log>")
sys.exit(1)

file_path = sys.argv[1]
main(file_path)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# export PYTHONPATH=$HOME/code/mvsim/build/:$PYTHONPATH
#
# Demo with N robots:
# for i in $(seq 1 25); do bash -c "mvsim_tutorial/python/simple-obstacle-avoidance.py --vehicle veh${i} &"; done
# for i in $(seq 1 25); do bash -c "examples_python/simple-obstacle-avoidance.py --vehicle veh${i} &"; done
#
# ---------------------------------------------------------------------

Expand Down Expand Up @@ -81,7 +81,7 @@ def evalObstacleAvoidance(obs: ObservationLidar2D_pb2.ObservationLidar2D):
# Force vectors
resultantForce = [0, 0]

#obsWeight = 20.0 / len(obs.scanRanges)
# obsWeight = 20.0 / len(obs.scanRanges)
obsWeight = 1

for idx, r in enumerate(obs.scanRanges):
Expand Down Expand Up @@ -138,7 +138,7 @@ def onLidar2DMessage(msgType, msg):
global prevLidarMsgTimestamp
global prevGlobalGoalTimestamp, prevGlobalGoal

assert(msgType == "mvsim_msgs.ObservationLidar2D")
assert (msgType == "mvsim_msgs.ObservationLidar2D")
p = ObservationLidar2D_pb2.ObservationLidar2D()
p.ParseFromString(bytes(msg))
# print("[lidar callback] received:\n ranges=\n" + str(p.scanRanges) + "\n validRanges=" + str(p.validRanges))
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion formatter.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# formatter.sh
find modules/ mvsim_node_src/ mvsim_tutorial/cpp/ mvsim-cli/ tests/ -iname *.h -o -iname *.hpp -o -iname *.cpp -o -iname *.c | xargs clang-format-14 -i
find modules/ mvsim_node_src/ examples_cpp/ mvsim-cli/ tests/ -iname *.h -o -iname *.hpp -o -iname *.cpp -o -iname *.c | xargs clang-format-14 -i

0 comments on commit a263ea7

Please sign in to comment.