FTH 4 · Operating a real humanoid|INEMA.CLUB-PRO

Lesson 7 · 15 min

Log and diagnose: logs and telemetry

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.

Start the lesson
Laptop on a dark desk showing blurred timelines of a recorded session, with an external drive plugged in and a robot on the gantry in the background.

In this lesson you will

  1. 1MCAP: a file with an index and a summary at the end
  2. 2Record without ROS (mcap library) and with ROS (ros2 bag -s mcap)
  3. 3Read the count, duration, and rate from the summary
  4. 4Find the fall inside the log

Goal: record a G1 session to MCAP, with and without ROS 2, and check the messages, the duration, and the fall in the log.

01From topic to diagnosis

Click each step.

Click each block in the diagram to see what it does.

02Record without ROS and read

The simulator drops the G1 at t = 2 s, with no command: it falls. gravar.py saves 1200 messages (6 s at 200 Hz) and ler_log.py reads the file back.

Terminal · record and read
F=${FTH:-$HOME/fth}; cd $F/operar && . $F/.venv/bin/activate
python3 kit/sim.py --s 8 --soltar-em 2 &
python3 kit/gravar.py $F/sessao.mcap --n 1200; echo "saída: $?"
wait
python3 kit/ler_log.py $F/sessao.mcap; echo "saída: $?"
Excerpt · kit/gravar.py
        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.

03Record 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: $?"
Example from the repository
arquivo: bag_lowstate_0.mcap · 1 canal(is)
canal /lowstate (cdr): 968 mensagens
mensagens: 968
duração: 4.8 s
taxa média ≈ 200 Hz
saída: 0

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.

04Practice

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.

05Lesson quiz

The explanation appears after your answer.

Question 1 of 4

ler_log.py said "MCAP sem resumo". What most likely happened?skill

06In three sentences

RecordMCAP with the right topics, without and with ROS 2.
CloseIf it is not closed properly, the file is left without a summary.
ReadCount, duration, rate, and the fall, from the file itself.

Going further

Previous lessonNext lesson