- 3.0.2 Documentation
|
CT is middleware free. Therefore, you are not bound to use ROS or catkin. However, for the sake of simplicity we will use catkin in this tutorial. In case you need a refresher on catkin, please go through the tutorials here. Make sure you have succesfully downloaded and compiled CT according to our How to use the Control Toolbox instructions. Afterwards go to your catkin workspace and create a new package
In this example, we made my_ct_project dependent on all CT packages. This is not strictly necessary, however there is no harm to it either.
First, we are going to simulate the dynamics of a damped oscillator. Let's create our main file
So what happens in this code? We first include ct/core.h. This includes all relevant headers from CT Core. Other CT modules have similar header files such as ct/rbd.h . If you were to include ct/rbd.h you would not have to include ct/core.h anymore. It is automatically included.
Then, we create a state vector and set it to zero. Afterwards, we can create a shared pointer to a ct::core::SecondOrderSystem which is a damped oscillator. It is derived from type ct::core::System, which means we can directly plug it into a ct::core::Integrator. Here, we have many choices such as ct::core::IntegratorEuler or ct::core::ODE45. Here, we chose a fourth-order Runge-Kutta integrator. We then simulate (integrate) it forward for 1 second with a time step of 0.001 seconds. Finally, we print the new state.
In the example above, we have been using an oscillator that is provided with CT. However, we might want to model our own system. Here, we will model a simple mass point subject to friction. However, if you are interested in more sophisticated models, especially Rigid Body Dynamics, make sure you check out the tutorials in ct_rbd as well.
First we create our system within a header Masspoint.h
As before, we can now integrate this system forward