Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add system tests CI draft #356

Merged
merged 40 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4a50f52
add system tests CI draft
whoenig Nov 15, 2023
6745b6b
attempt for github to see new workflow file
whoenig Nov 15, 2023
a97e454
change CI
whoenig Nov 15, 2023
359e214
manual colcon build
whoenig Nov 15, 2023
f04ac79
dbg
whoenig Nov 15, 2023
0a21adc
dbg2
whoenig Nov 15, 2023
fa8ba34
dbg3
whoenig Nov 15, 2023
76efa01
dbg4
whoenig Nov 15, 2023
c6688b0
dbg5
whoenig Nov 15, 2023
9baae2b
dbg6
whoenig Nov 15, 2023
538af76
add flight test script
whoenig Nov 15, 2023
6df9b2b
dbg7
whoenig Nov 15, 2023
40e176f
dbg8
whoenig Nov 15, 2023
7acaa04
dbg9
whoenig Nov 15, 2023
da69278
flight test1
whoenig Nov 15, 2023
e1fc36e
dbg10
whoenig Nov 15, 2023
2ab206c
dbg11
whoenig Nov 15, 2023
b948a67
dbg12
whoenig Nov 15, 2023
742019f
added all of the changes wolfgang asked (except shutil); saved the pd…
julienthevenoz Nov 16, 2023
7d8e822
there was a typo in the systemtests.yml
julienthevenoz Nov 16, 2023
653a4bc
yaml debug
julienthevenoz Nov 16, 2023
2a4b7f4
dbg
julienthevenoz Nov 16, 2023
13c39dd
dbg
julienthevenoz Nov 17, 2023
4809edd
"dbg2"
julienthevenoz Nov 17, 2023
4e9ce47
one more dbg
julienthevenoz Nov 21, 2023
0e14265
still working on it
julienthevenoz Nov 22, 2023
b744ab0
latest version
julienthevenoz Nov 22, 2023
04cf9b0
trying to upload the logs
julienthevenoz Nov 22, 2023
b1aae2b
Everything should work
julienthevenoz Nov 24, 2023
f79e6f8
make drone fly lower
julienthevenoz Nov 24, 2023
5ec8bb8
renamed newsub.py to run_test.py and adjusted altitude constant for f…
julienthevenoz Nov 24, 2023
c435d8f
cleanup
julienthevenoz Nov 24, 2023
c90f972
Addressed wolfgang's comments on draft #356
julienthevenoz Nov 27, 2023
7b1d82d
adressed issues
julienthevenoz Nov 28, 2023
ced6a2e
addressed 2 minor comments
julienthevenoz Nov 30, 2023
860194a
addressed two minor comments
julienthevenoz Nov 30, 2023
979ad37
dbg
julienthevenoz Nov 30, 2023
24f0911
dbg
julienthevenoz Nov 30, 2023
8154976
typo
julienthevenoz Nov 30, 2023
7da90ba
Addressed two minor comments : cleanup
julienthevenoz Nov 30, 2023
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
57 changes: 57 additions & 0 deletions .github/workflows/systemtests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: System Tests

on:
push:
branches: [ "feature_systemtests" ]
# manual trigger
workflow_dispatch:

jobs:
build:
runs-on: self-hosted
steps:
- name: Create workspace
run: |
pwd
rm -rf ros2_ws
mkdir -p ros2_ws/src
- name: Checkout motion capture package
run: |
cd ros2_ws/src
ls motion_capture_tracking || git clone --branch ros2 --recursive https://github.com/IMRCLab/motion_capture_tracking.git
- name: Checkout Crazyswarm2
uses: actions/checkout@v4
with:
path: ros2_ws/src/crazyswarm2
submodules: 'recursive'
- name: Build workspace
run: |
source /opt/ros/humble/setup.bash
cd ros2_ws
colcon build --symlink-install

- name: Flight test
run: |
cd ros2_ws
source /opt/ros/humble/setup.bash
. install/local_setup.bash
export ROS_LOCALHOST_ONLY=1
python3 src/crazyswarm2/systemtests/newsub.py

- name: Upload files
uses: actions/upload-artifact@v3
with:
name: bagfiles
path: ros2_ws/bagfiles/
whoenig marked this conversation as resolved.
Show resolved Hide resolved

# - name: build and test ROS 2
# uses: ros-tooling/action-ros-ci@v0.3
# with:
# package-name: |
# crazyflie
# crazyflie_examples
# crazyflie_interfaces
# crazyflie_py
# crazyflie_sim
# target-ros2-distro: humble
# vcs-repo-file-url: rosinstall
2 changes: 1 addition & 1 deletion crazyflie/config/crazyflies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
robots:
cf231:
enabled: true
uri: radio://0/80/2M/E7E7E7E7E7
uri: radio://0/60/2M/E7E7E7E7E7
julienthevenoz marked this conversation as resolved.
Show resolved Hide resolved
initial_position: [0, 0, 0]
type: cf21 # see robot_types
# firmware_params:
Expand Down
53 changes: 53 additions & 0 deletions systemtests/mcap_read_write.py
whoenig marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from pathlib import Path
from rclpy.serialization import deserialize_message
from rosidl_runtime_py.utilities import get_message
from std_msgs.msg import String
import rosbag2_py
import csv

class McapHandler:
def __init__(self):
pass

def read_messages(self, input_bag: str):
reader = rosbag2_py.SequentialReader()
reader.open(
rosbag2_py.StorageOptions(uri=input_bag, storage_id="mcap"),
rosbag2_py.ConverterOptions(
input_serialization_format="cdr", output_serialization_format="cdr"
),
)
topic_types = reader.get_all_topics_and_types()

def typename(topic_name):
for topic_type in topic_types:
if topic_type.name == topic_name:
return topic_type.type
raise ValueError(f"topic {topic_name} not in bag")

while reader.has_next():
topic, data, timestamp = reader.read_next()
msg_type = get_message(typename(topic))
msg = deserialize_message(data, msg_type)
yield topic, msg, timestamp
del reader

def write_mcap_to_csv(self, inputbag:str, outputfile:str):
try:
print("Translating .mcap to .csv")
f = open(outputfile, 'w+')
writer = csv.writer(f)
for topic, msg, timestamp in self.read_messages(inputbag):
writer.writerow([timestamp, msg.transforms[0].transform.translation.x, msg.transforms[0].transform.translation.y, msg.transforms[0].transform.translation.z])
f.close()
except FileNotFoundError:
print(f"McapHandler : file {outputfile} not found")
exit(1)




if __name__ == "__main__":
yo = McapHandler()
# # yo.write_mcap_to_csv('Home/julien/ros2_ws/bagfiles/bag_06_11_2023-17:11:23/bag_06_11_2023-17:11:23_0.mcap','Home/julien/ros2_ws/bagfiles/bag_06_11_2023-17:11:23/bag_06_11_2023-17:11:23_0.csv')
yo.write_mcap_to_csv('/home/julien/Desktop/IMRC/IMRC-shared/bags/multibag/multibag_0.mcap','/home/julien/Desktop/IMRC/IMRC-shared/bags/multibag/multibag_0.csv')
whoenig marked this conversation as resolved.
Show resolved Hide resolved
52 changes: 52 additions & 0 deletions systemtests/newsub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
from subprocess import Popen
import time
import os
import signal
from mcap_read_write import McapHandler
from datetime import datetime
from pathlib import Path
from plotter_class import Plotter


if __name__ == "__main__":

command = "source install/setup.bash && ros2 launch crazyflie launch.py"
launch_crazyswarm = Popen(command, shell=True, stderr=True,
stdout=True, text=True, executable="/bin/bash", preexec_fn=os.setsid)
time.sleep(3)
bagname = 'bag_' + datetime.now().strftime('%d_%m_%Y-%H_%M_%S')
command = f"mkdir bagfiles && cd bagfiles && ros2 bag record -s mcap -o {bagname} /tf"
whoenig marked this conversation as resolved.
Show resolved Hide resolved
start_rosbag = Popen(command, shell=True, stderr=True,
stdout=True, text=True, executable="/bin/bash", preexec_fn=os.setsid)
command = "ros2 run crazyflie_examples figure8"
whoenig marked this conversation as resolved.
Show resolved Hide resolved
start_test = Popen(command, shell=True, stderr=True,
stdout=True, text=True, executable="/bin/bash", preexec_fn=os.setsid)
time.sleep(30)
os.killpg(os.getpgid(start_test.pid), signal.SIGTERM) #kill start_test process and all of its child processes
os.killpg(os.getpgid(start_rosbag.pid), signal.SIGTERM) #kill rosbag
os.killpg(os.getpgid(launch_crazyswarm.pid), signal.SIGTERM) #kill crazyswarm

print("Flight finished")

#test done, now we compare the ideal and real trajectories

#create a file that translates the .mcap format of the rosbag to .csv
writer = McapHandler()
#path = str(Path(__file__).parent /"bags/tfbag.mcap")
whoenig marked this conversation as resolved.
Show resolved Hide resolved

### attention le bagname est different du bagfile par un _0
whoenig marked this conversation as resolved.
Show resolved Hide resolved
inputbag = "bagfiles/" + bagname + '/' + bagname + '_0' + '.mcap'
output_csv = "bagfiles/" + bagname + '/' + bagname + '_0' + '.csv'

writer.write_mcap_to_csv(inputbag, output_csv)

output_pdf = "bagfiles/" + bagname + '/' + 'Results_'+ datetime.now().strftime('%d_%m_%Y-%H_%M_%S')

rosbag_csv = output_csv

test_file = "../crazyflie_examples/crazyflie_examples/data/figure8.csv"
paul = Plotter()
paul.create_figures(test_file, rosbag_csv, output_pdf)

exit()
Loading