Hello,
I am trying to add a new WrapObject to an existing body in an osim file but can't manage to figure it out (I'm new to both OpenSim and C++). I think the problem may be that when I'm getting a reference to the body (called "proximal_row"), it's a read-only reference, not an updatable one. I've copied the code section below, so if you have any ideas for what might work, I'd appreciate it!
For context, I'm trying to use this WrapObject to define a GeometryPath, which I'd then use to construct a PathActuator. I included some of that additional code as well (although it seems my code is currently failing somewhere between my "Created wrist cylinder" and "Added path wrap" debug statements) so if you have any other suggestions relating to path actuator construction, I'd appreciate those as well!
Thanks
//Create wrap object
OpenSim::Body& proximal_row = wristTremorModel.updBodySet().get("proximal_row");
WrapCylinder *wristCylinder = new WrapCylinder();
wristCylinder->setRadius(0.025);
wristCylinder->setLength(0.1);
wristCylinder->connectToModelAndBody(wristTremorModel, proximal_row);
cout << "Created wristCylinder" << endl;
GeometryPath *agonistPath = new GeometryPath();
agonistPath->addPathWrap(*wristCylinder);
cout << "Added path wrap" << endl;
//wristTremorModel.addComponent(agonistPath);
//Construct path actuator and define path geometry
PathActuator *agonistAct = new PathActuator();
wristTremorModel.addForce(agonistAct);
agonistAct->set_GeometryPath(*agonistPath);
cout << "Added geometry path" << endl;
agonistAct->addNewPathPoint("distal_anchor_P1", *distal_anchor, Vec3(0, 0, 0.02));
agonistAct->addNewPathPoint("proximal_anchor_P1", *proximal_anchor, Vec3(0, 0, 0.05));
cout << "Added path points" << endl;
//Add agonist path actuator to model
cout << "Added agonist actuator" << endl;
Add WrapObject to existing Body
- Caitlin Romanczyk
- Posts: 5
- Joined: Wed May 16, 2018 8:44 am
- Thomas Uchida
- Posts: 1792
- Joined: Wed May 16, 2012 11:40 am
Re: Add WrapObject to existing Body
This example might be helpful: https://github.com/opensim-org/opensim- ... pperDevice (see, in particular, buildHopperModel.cpp at line 151: https://github.com/opensim-org/opensim- ... l.cpp#L151). The example is written in 4.0 but the code should be similar.
- Caitlin Romanczyk
- Posts: 5
- Joined: Wed May 16, 2018 8:44 am
Re: Add WrapObject to existing Body
Thank you! That example helped a lot. For anyone else with the same issue in the future, this is what ended up working for me in the end:
OpenSim::Body& proximal_row = wristTremorModel.updBodySet().get("proximal_row");
WrapCylinder *wristCylinder = new WrapCylinder();
wristCylinder->setName("wristCylinder");
wristCylinder->setRadius(0.025);
wristCylinder->setLength(0.1);
proximal_row.addWrapObject(wristCylinder);
OpenSim::Body& proximal_row = wristTremorModel.updBodySet().get("proximal_row");
WrapCylinder *wristCylinder = new WrapCylinder();
wristCylinder->setName("wristCylinder");
wristCylinder->setRadius(0.025);
wristCylinder->setLength(0.1);
proximal_row.addWrapObject(wristCylinder);