5#include <Eigen/Geometry>
21namespace tinyrobotics {
29 template <
typename Scalar,
int nq>
44 std::vector<Link<Scalar>>
links = {};
47 std::vector<Joint<Scalar>>
joints = {};
59 Eigen::Matrix<Scalar, 3, 1>
gravity = {0, 0, -9.81};
73 for (
auto link :
links) {
74 if (link.name ==
name) {
89 for (
auto link :
links) {
90 if (link.name ==
name) {
91 return links[link.parent];
95 throw std::runtime_error(
"Error! Parent of Link [" +
name +
"] not found!");
106 for (
auto link :
links) {
107 if (link.joint.name ==
name) {
119 const int spacing = 25;
120 const std::string separator(150,
'*');
121 std::cout << separator << std::endl;
122 std::cout <<
"Model name : " <<
name << std::endl;
123 std::cout <<
"No. of links : " <<
links.size() << std::endl;
124 std::cout <<
"No. of joints : " <<
joints.size() << std::endl;
125 std::cout <<
"No. of actuated joints : " <<
n_q << std::endl;
126 std::cout <<
"Base link name : " <<
links[
base_link_idx].name << std::endl << std::endl;
127 std::cout <<
"Model Mass : " <<
mass << std::endl;
128 std::cout << std::left << std::setw(spacing) <<
"Index" << std::setw(spacing) <<
"Link Name"
129 << std::setw(spacing) <<
"Joint Name [idx]" << std::setw(spacing) <<
"Joint Type"
130 << std::setw(spacing) <<
"Parent Name [idx]" << std::setw(spacing) <<
"Children Names"
132 for (
const auto& link :
links) {
133 std::string children_names;
134 for (
const auto& child_link_idx : link.child_links) {
135 children_names +=
links[child_link_idx].name +
" ";
138 std::string parent_name =
"";
140 if (link.parent != -1) {
141 parent_link =
links[link.parent];
142 parent_name = parent_link.
name;
143 parent_idx = link.parent;
145 std::cout << std::left << std::setw(spacing) << link.idx << std::setw(spacing) << link.name
146 << std::setw(spacing) << link.joint.name +
"[" + std::to_string(link.joint.idx) +
"]"
147 << std::setw(spacing) << link.joint.get_type() << std::setw(spacing)
148 << parent_name +
" [" + std::to_string(parent_idx) +
"]" << std::setw(spacing)
149 << children_names << std::endl;
151 std::cout << separator << std::endl;
160 Eigen::Matrix<Scalar, nq, 1> q(
n_q);
171 Eigen::Matrix<Scalar, nq, 1> q(
n_q);
182 template <
typename NewScalar>
191 for (
auto& joint :
joints) {
192 new_model.
joints.push_back(joint.template cast<NewScalar>());
194 for (
auto& link :
links) {
195 new_model.
links.push_back(link.template cast<NewScalar>());
197 new_model.
data =
data.template cast<NewScalar>();
Contains the Data struct which stores the results of various model algorithms.
Contains struct for representing a joint in a tinyrobotics model.
Contains struct for representing a joint in a tinyrobotics model.
A data struct for storing results of various model algorithms.
Definition: Data.hpp:18
Represents a joint in a tinyrobotics model which connects two links.
Definition: Joint.hpp:28
Represents a link in a tinyrobotics model.
Definition: Link.hpp:16
std::string name
Name of the link.
Definition: Link.hpp:19
A tinyrobotics model.
Definition: Model.hpp:30
std::vector< int > parent
Vector of parent link indices of the links which are non-fixed.
Definition: Model.hpp:56
int n_links
Number of links in the model.
Definition: Model.hpp:35
Joint< Scalar > get_joint(const std::string &name) const
Get the joint in the model by name.
Definition: Model.hpp:105
Data< Scalar, nq > data
Stores the results of the models algorithms.
Definition: Model.hpp:65
Scalar mass
Total mass of the model.
Definition: Model.hpp:62
std::vector< Joint< Scalar > > joints
Vector of joints in the model.
Definition: Model.hpp:47
Link< Scalar > get_parent_link(const std::string &name) const
Get the parent link of a link in the model by name.
Definition: Model.hpp:88
int n_q
Number of configuration coordinates (degrees of freedom) in the model.
Definition: Model.hpp:41
Eigen::Matrix< Scalar, nq, 1 > random_configuration() const
Get a random configuration vector for the model.
Definition: Model.hpp:169
Link< Scalar > get_link(const std::string &name) const
Get a link in the model by name.
Definition: Model.hpp:72
void show_details()
Display details of the model.
Definition: Model.hpp:118
Eigen::Matrix< Scalar, 3, 1 > gravity
Gravitational acceleration experienced by model.
Definition: Model.hpp:59
Eigen::Matrix< Scalar, nq, 1 > home_configuration() const
Get a configuration vector for the model of all zeros.
Definition: Model.hpp:158
std::string name
Name of the model.
Definition: Model.hpp:32
int base_link_idx
Index of the base link in the models links vector.
Definition: Model.hpp:50
Model< NewScalar, nq > cast()
Casts the model to a new scalar type.
Definition: Model.hpp:183
std::vector< int > q_idx
Vector of indices of links in the models link vector that have a non-fixed joint.
Definition: Model.hpp:53
int n_joints
Number of joints in the model.
Definition: Model.hpp:38
std::vector< Link< Scalar > > links
Vector of links in the model.
Definition: Model.hpp:44