multicore module: two obj files in one cpp

49 views
Skip to first unread message

yibing Yan

unread,
Sep 30, 2022, 11:08:40 PM9/30/22
to ProjectChrono
hi,
I am trying to use the multicore module. After learning for several days, every thing seems good. Then there are some new questions.
1.  How can I add two different .obj files in one .cpp? I used the same code to add two objs, but it seems that it will show the same objects, one of them is not what I want to show and the other one is right. It shows the first obj I called.
I compared it with many examples, it seems every step is taken into account.

I used the following code:
/***********************************************************************/
std::shared_ptr<ChBody> AddSampler(ChSystemMulticoreNSC* sys) {
    auto object = std::shared_ptr<ChBody>(sys->NewBody());
    sys->AddBody(object);

    object->SetIdentifier(-202);
    //object->SetName("object");
    object->SetMass(2000); //14715
    object->SetInertiaXX(40.0 * ChVector<>(1, 1, 0.2));
    object->SetPos(ChVector<>(0, 0, 1.2+4.25));

    object->SetPos_dt(init_vel); //    Set the linear speed.
    object->SetWvel_loc(init_omg); //Set the rotation speed from given angular speed (expressed in local csys)
    object->SetCollide(true);
    object->SetBodyFixed(false);

    auto object_mat = ChMaterialSurface::DefaultMaterial(contact_method);
    object_mat->SetFriction(object_friction);
    object_mat->SetRestitution(object_restitution);

    std::string tire_mesh_file = GetChronoDataFile("models/mixer/yyb(0.02-2).obj");
    double sphere_r = 0.005;
    auto trimesh = geometry::ChTriangleMeshConnected::CreateFromWavefrontFile(tire_mesh_file);

    object->GetCollisionModel()->ClearModel();
    object->GetCollisionModel()->AddTriangleMesh(object_mat, trimesh, false, false, ChVector<>(0),
                                                 ChMatrix33<>(1), sphere_r); //Add a triangle mesh to this collision model.
   
    object->GetCollisionModel()->SetFamily(3);
    object->GetCollisionModel()->BuildModel();

    auto trimesh_shape = chrono_types::make_shared<ChTriangleMeshShape>();
    trimesh_shape->SetMesh(trimesh);
    object->AddVisualShape(trimesh_shape);

    return object;
}

std::shared_ptr<ChBody> AddSpoon(ChSystemMulticoreNSC* sys) {
    auto object = std::shared_ptr<ChBody>(sys->NewBody());

    object->SetIdentifier(-203);
    //object->SetName("spoon");
    object->SetMass(200);
    object->SetInertiaXX(40.0 * ChVector<>(1, 1, 0.2));
    object->SetPos(ChVector<>(2, 0, 1.2+4.25));
    object->SetPos_dt(ChVector<>(0, 0, 0)); //    Set the linear speed.
    object->SetWvel_loc(ChVector<>(0, 0, 20)); //Set the rotation speed from given angular speed (expressed in local csys)
    object->SetCollide(true);
    object->SetBodyFixed(false);

    auto object_mat = ChMaterialSurface::DefaultMaterial(contact_method);
    object_mat->SetFriction(object_friction);
    object_mat->SetRestitution(object_restitution);

    std::string tire_mesh_file = GetChronoDataFile("models/mixer/spoon(0.02).obj");
    double sphere_r = 0.005;
    auto trimesh = geometry::ChTriangleMeshConnected::CreateFromWavefrontFile(tire_mesh_file);

    object->GetCollisionModel()->ClearModel();
    object->GetCollisionModel()->AddTriangleMesh(object_mat, trimesh, false, false, ChVector<>(0), ChMatrix33<>(1), sphere_r);
    object->GetCollisionModel()->SetFamily(4);
    object->GetCollisionModel()->BuildModel();

    sys->AddBody(object);

    auto trimesh_shape = chrono_types::make_shared<ChTriangleMeshShape>();
    trimesh_shape->SetMesh(trimesh);
    object->AddVisualShape(trimesh_shape);

    return object;
}
/*********************************************************************************/

and when I call them in the main function, it shows two same objects as the first obj I called.
I've been trying for days and still don't know what's going on.

2. The second question is that how to realize different movement with two objects that have fixed relative position, such as one object rotate around the z-axis, and this object also has translation with another object as a whole.
For example, I can think of that giving them the same coordinate system, set the same pos_dt  and different wvel_loc. But, I am worried that if they subject to force, there relative position will be broken.
I was wondering if there are ant demos regarding this or functions can set relative position.

Thank you so much in advance.
yyb
Reply all
Reply to author
Forward
0 new messages