|
bitsim
Model, simulate, estimate and control robots in C++
|
This example accompanies the first lesson of the robotics course. It shows how to create and use coordinate frames with bitsim. You need bitsim configured with Chrono support to run it.
bitsim does not wrap frames. It uses chrono::ChFrame<> directly, and the robots in src/bitsim/rigid_bodies/chrono_robots are built from it, so what you learn here applies to the rest of the library.
A robot has to relate many things to each other: where it is in the world, where its sensors are mounted on it, and where an obstacle is relative to a sensor. Each of these is simple in its own frame of reference. A frame is a position and an orientation with respect to a parent frame. In other words it tells us where the origin of a coordinate system is, and where its axes point.
We use a robot at \((2, 1, 0)\) turned \(90^\circ\) around \(z\), and a range sensor on its left side that looks to the left. An obstacle is at \((0, 1, 0.1)\) in the world. The frames are
The code follows the naming used in the rest of bitsim:
The benefit is that the inner letters cancel, so mistakes are easy to spot: X_WR * X_RS gives X_WS and X_WS * p_S gives p_W, whereas X_RS * X_WR does not cancel and has no meaning here.
The default constructor gives the identity frame, and a position alone gives a frame with the same orientation as its parent. There are several ways to specify an orientation and they are equivalent.
The rotation matrix version is worth a closer look. Its columns are the axes of the new frame seen from the parent. The robot is turned \(90^\circ\) so its \(x\) axis points along the world \(y\) axis. The output below prints every frame that way.
A frame maps coordinates from itself to its parent. For a rotation \(R_{WR}\) and a translation \(t_{WR}\)
\[p_W = R_{WR} \, p_R + t_{WR} \]
A direction has no location, so only the rotation applies. This distinction matters: a sensor's mounting point is a point but the force on a wheel or the direction a sensor looks along are directions.
We know how the sensor is mounted on the robot and where the robot is in the world. The pose of the sensor in the world follows by composing the two
Composition does not commute. X_RS * X_WR below is a different frame, and it does not mean anything physically. Chrono also has operator>> which composes in the reverse order. We stick to operator* since it reads like the maths and like the rest of bitsim.
The inverse gives the opposite relationship: X_SW is the pose of the world in the sensor. It answers the question a robot actually asks, which is what something looks like from where the sensor is.
The obstacle comes out on the sensor's \(x\) axis, so it is straight ahead, at a range of 1.8 m. Note that the origin of X_SW is not simply minus the origin of X_WS, since the inverse also has to undo the rotation
\[R_{SW} = R_{WS}^T \quad t_{SW} = -R_{WS}^T \, t_{WS} \]
Composing a frame with its inverse gives the identity.
A chrono::ChBody is a frame that the simulation moves. GetFrameRefToAbs() returns its pose in the world. X_RS stays constant, because the sensor is rigidly mounted, so we only recompute X_WS.
bitsim provides CHRONO_RobotPose to monitor a body and convert between its local coordinates and the world.
We spin the robot by \(90^\circ\) over one second. The robot's origin stays where it is, the sensor swings around it, and the obstacle, which has not moved, is now somewhere else in the sensor frame.
With --render the robot keeps spinning in an Irrlicht window, slower than in section 5 so that you can follow the numbers. The frames are drawn with their names, and \(x\) is red, \(y\) is green and \(z\) is blue. The yellow line goes from the sensor to the obstacle.
Watch the panel at the top right. obstacle in W never changes since the obstacle does not move, whereas obstacle in S changes all the time. It is the same point seen from a frame that moves. The range changes too, because the sensor is not at the centre of the rotation.