Add WrapObject to existing Body
Posted: Wed Aug 08, 2018 8:13 am
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;
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;