A method for controlling a robot, which moves an ensemble that includes an arm and a tool, includes receiving from the robot, at one or more times, an arm-tracking signal, which indicates an armpose of the arm relative to a robot coordinate system (RCS) of the robot, deriving, from the arm-tracking signal, respective RCS-poses of at least one portion of the ensemble, relative to the RCS, at the times, receiving, from a tracking system, a sensor-tracking signal, which indicates a sensor-pose of at least one sensor, which belongs to the tracking system and is coupled to the ensemble, relative to a tracking-system coordinate system (TCS) of the tracking system, deriving, from the sensor-tracking signal, respective TCS-poses of the portion of the ensemble, relative to the TCS, at the times, registering the RCS to the TCS based on the RCS-poses and the TCS-poses, and, based on the registering, controlling the robot.