MCPcopy Create free account
hub / github.com/Simple-Robotics/Simple / createBallsScene

Function createBallsScene

tests/forward/simulation-combine-constraints.cpp:39–118  ·  view source on GitHub ↗

\brief Creates a scene of 10 balls, all lying on a floor. \param reduced_collision_pairs activate only the collision pair between balls and floor.

Source from the content-addressed store, hash-verified

37/// \brief Creates a scene of 10 balls, all lying on a floor.
38/// \param reduced_collision_pairs activate only the collision pair between balls and floor.
39std::tuple<ModelHandle, GeometryModelHandle, Eigen::VectorXd>
40createBallsScene(bool prismatic_joint, bool collision_plane, bool inter_colision)
41{
42 Model model;
43 GeometryModel geom_model;
44
45 // Add plane
46 hpp::fcl::CollisionGeometryPtr_t plane_ptr(new hpp::fcl::Halfspace(0., 0., 1., 0.));
47 const GeometryObject plane_geom = GeometryObject("plane", 0, SE3::Identity(), plane_ptr);
48 GeomIndex plane_id = geom_model.addGeometryObject(plane_geom);
49
50 // Add balls
51 const std::size_t nballs = 10;
52 const double radius = 1.0;
53 const double mass = 1.0;
54 for (std::size_t i = 0; i < nballs; ++i)
55 {
56 const std::string name = "ball_" + std::to_string(i);
57 const std::string joint_name = "joint_" + std::to_string(i);
58 const std::string frame_name = "frame_" + std::to_string(i);
59 const Inertia inertia = Inertia::FromSphere(mass, radius);
60 const JointIndex parent = 0;
61 JointIndex joint_id;
62 SE3 placement = SE3::Identity();
63 ;
64 if (prismatic_joint)
65 {
66 placement.translation() = Eigen::Vector3d(static_cast<double>(i) * 2 * radius * 1.1, 0, 0);
67 const JointModelPZ joint = JointModelPZ();
68 joint_id = model.addJoint(parent, joint, placement, joint_name);
69 }
70 else
71 {
72 const JointModelFreeFlyer joint = JointModelFreeFlyer();
73 joint_id = model.addJoint(parent, joint, placement, joint_name);
74 }
75 model.appendBodyToJoint(joint_id, inertia);
76 hpp::fcl::CollisionGeometryPtr_t ball_ptr(new hpp::fcl::Sphere(radius));
77 const GeometryObject ball_geom = GeometryObject(name, joint_id, placement, ball_ptr);
78 GeomIndex ball_id = geom_model.addGeometryObject(ball_geom);
79 if (collision_plane)
80 {
81 CollisionPair col_pair(plane_id, ball_id);
82 geom_model.addCollisionPair(col_pair);
83 }
84 }
85
86 if (inter_colision)
87 {
88 for (size_t i = 0; i < geom_model.geometryObjects.size(); ++i)
89 {
90 for (size_t j = i + 1; j < geom_model.geometryObjects.size(); ++j)
91 {
92 CollisionPair col_pair(i, j);
93 geom_model.addCollisionPair(col_pair);
94 }
95 }
96 }

Callers 3

test_static_sceneFunction · 0.85
test_moving_sceneFunction · 0.85
test_constraint_sceneFunction · 0.85

Calls

no outgoing calls

Tested by 3

test_static_sceneFunction · 0.68
test_moving_sceneFunction · 0.68
test_constraint_sceneFunction · 0.68