After a fall, the question is always the same: what happened before? Without a log, the answer is a guess. In this lesson you record a G1 session to MCAP, with and without ROS, and read the file back: how many messages, how long, and whether the fall is in there.
dado = {"tick": s.tick, "imu_quat": list(s.imu_state.quaternion),
"q": [s.motor_state[i].q for i in range(op.N)],
"dq": [s.motor_state[i].dq for i in range(op.N)],
"tau_est": [s.motor_state[i].tau_est for i in range(op.N)]}
Example from the repository
simulador: G1 29 motores · DDS domínio 1 em lo · 8 s · suspenso: não · elástico solta em t = 2 s
gravado: ~/fth/sessao.mcap · 1200 mensagens de rt/lowstate
saída: 0
simulador: fim em t = 8.0 s · robô no chão
arquivo: sessao.mcap · 1 canal(is)
canal rt/lowstate (json): 1200 mensagens
mensagens: 1200
duração: 6.0 s
taxa média ≈ 200 Hz
queda no registro (inclinação acima de 40°): sim
saída: 0
1200 messages in 6 s, and the fall is in the log. The count is exact because the recorder stops at N messages.
03 · Record with ROS 2 (the lesson 6 container)
ros2 bag record saves /lowstate to MCAP for 5 s and the same ler_log.py reads the file. The message comes in CDR (the ROS format): the reader counts and measures, without decoding.
Terminal · ros2 bag record -s mcap
F=${FTH:-$HOME/fth}; cd $F/operar && . $F/.venv/bin/activate
python3 kit/sim.py --s 15 --suspenso > /dev/null &
until python3 kit/monitor.py --s 0.5 > /dev/null; do sleep 0.5; done
rm -rf $F/bag_lowstate
docker run --rm --network host -v $F:/dados --user $(id -u):$(id -g) -e HOME=/tmp fth-humble \
timeout -s INT 5 ros2 bag record -s mcap -o /dados/bag_lowstate /lowstate > /dev/null 2>&1
wait
python3 kit/ler_log.py $F/bag_lowstate/bag_lowstate_0.mcap; echo "saída: $?"
The count and duration change on every run (they depend on when the container started and stopped recording); the average rate stays around 200 Hz.
04 · Practice
Record, read, find the fall.
E1 · Session without ROS
5 min
Run the record and read block. Then run ler_log.py on a file that does not exist and look at the message.
Done when:python3 kit/ler_log.py ~/fth/sessao.mcap; echo "saída: $?" → mensagens: 1200, queda no registro (inclinação acima de 40°): sim and saída: 0.
E2 · Session with ROS 2
10 min
Run the ros2 bag block. Compare the count with a colleague's (or with your second run) and explain the difference.
Done when:python3 kit/ler_log.py ~/fth/bag_lowstate/bag_lowstate_0.mcap → canal /lowstate (cdr), taxa média ≈ 200 Hz and saída: 0.
05 · Lesson quiz
The explanation appears after your answer.
Question 1 of 4
ler_log.py said "MCAP sem resumo". What most likely happened?skill
Correct
The summary is written at the end. If the process is killed midway, the messages are left without the index; that is why ros2 bag is stopped with SIGINT (timeout -s INT), not with kill.
Not this one
The summary is written at the end. If the process is killed midway, the messages are left without the index; that is why ros2 bag is stopped with SIGINT (timeout -s INT), not with kill.Review: From topic to diagnosis
Question 2 of 4
Why not always record with ros2 bag record -a?
Correct
Choose the topics that answer the session's question. With telemetry, more is not better.