10 #include <argos3/core/simulator/entity/embodied_entity.h>
21 cpShape* pt_gripper_shape) :
23 m_cGripperEntity(c_gripper_entity),
24 m_ptGripperShape(pt_gripper_shape),
26 m_tConstraint(nullptr) {
27 m_ptGripperShape->sensor = 1;
29 m_ptGripperShape->data =
this;
30 m_tGrippeeAnchor = cpvzero;
45 cpvdist(cpBodyGetPos(cpShapeGetBody(m_ptGripperShape)),
46 cpBodyGetPos(cpShapeGetBody(m_pcGrippee->
GetShape()))) /
57 m_tGrippeeAnchor = cpvzero;
58 for(
SInt32 i = 0; i < cpArbiterGetCount(pt_arb); ++i) {
59 m_tGrippeeAnchor = cpvadd(m_tGrippeeAnchor, cpArbiterGetPoint(pt_arb, i));
61 m_tGrippeeAnchor = cpvmult(m_tGrippeeAnchor, 1.0f / cpArbiterGetCount(pt_arb));
63 CP_ARBITER_GET_BODIES(pt_arb, ptGripperBody, ptGrippeeBody);
64 m_fRestLength = cpvdist(cpBodyGetPos(ptGripperBody),
71 static cpFloat GRIPPING_SPRING_DAMPING = 0.99;
77 cpShapeGetBody(m_ptGripperShape),
78 cpShapeGetBody(pc_grippee->
GetShape()),
80 cpBodyWorld2Local(cpShapeGetBody(pc_grippee->
GetShape()),
84 GRIPPING_SPRING_DAMPING));
85 m_tConstraint->maxBias = 0.95f;
86 m_tConstraint->maxForce = 10000.0f;
88 m_pcGrippee = pc_grippee;
89 m_pcGrippee->
Attach(*
this);
98 cpConstraintFree(m_tConstraint);
99 m_tConstraint =
nullptr;
101 m_pcGrippee->
Remove(*
this);
102 m_pcGrippee =
nullptr;
111 m_cEmbodiedEntity(c_entity),
112 m_ptShape(pt_shape) {
114 m_ptShape->data =
this;
128 m_listGrippers.push_back(&c_gripper);
136 std::find(m_listGrippers.begin(), m_listGrippers.end(), &c_gripper);
137 if(it != m_listGrippers.end()) {
138 m_listGrippers.erase(it);
147 std::find(m_listGrippers.begin(), m_listGrippers.end(), &c_gripper);
148 if(it != m_listGrippers.end()) {
157 while(!m_listGrippers.empty()) {
158 m_listGrippers.back()->Release();
169 CP_ARBITER_GET_SHAPES(pt_arb, ptGripperShape, ptGrippableShape);
175 return (&(pcGripper->GetGripperEntity().GetParent()) != &(pcGrippable->GetEmbodiedEntity().GetParent()));
185 CP_ARBITER_GET_SHAPES(pt_arb, ptGripperShape, ptGrippableShape);
195 if(pcGripper->IsGripping() && !pcGripper->IsLocked()) {
197 cpSpaceAddPostStepCallback(
201 ptGrippableShape->data);
204 if(!pcGripper->IsGripping() && pcGripper->IsLocked()) {
205 pcGripper->CalculateAnchor(pt_arb);
207 cpSpaceAddPostStepCallback(
228 pcGripper->Grip(pcGrippable);
signed int SInt32
32-bit signed integer.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
int BeginCollisionBetweenGripperAndGrippable(cpArbiter *pt_arb, cpSpace *pt_space, void *p_data)
void AddConstraintBetweenGripperAndGrippable(cpSpace *pt_space, void *p_obj, void *p_data)
void RemoveConstraintBetweenGripperAndGrippable(cpSpace *pt_space, void *p_obj, void *p_data)
int ManageCollisionBetweenGripperAndGrippable(cpArbiter *pt_arb, cpSpace *pt_space, void *p_data)
This entity is a link to a body in the physics engine.
An entity that stores the state of a robot gripper.
void SetGrippedEntity(CEmbodiedEntity &c_entity)
Sets the embodied entity currently gripped by this gripper.
void ClearGrippedEntity()
Clears the reference to the embodied entity currently gripped by this gripper.
cpSpace * GetPhysicsSpace()
Real GetGrippingRigidity() const
void CalculateAnchor(cpArbiter *pt_arb)
void Grip(CDynamics2DGrippable *pc_grippee)
Real GetExtension() const
Returns the extension of the constraint.
CDynamics2DGripper(CDynamics2DEngine &c_engine, CGripperEquippedEntity &c_gripper_entity, cpShape *pt_gripper_shape)
void Release(CDynamics2DGripper &c_gripper)
void Remove(CDynamics2DGripper &c_gripper)
void Attach(CDynamics2DGripper &c_gripper)
CDynamics2DGrippable(CEmbodiedEntity &c_entity, cpShape *pt_shape)
CEmbodiedEntity & GetEmbodiedEntity()