@@ -73,6 +73,25 @@ class RoficomController
7373 _jointData.setPositionLimits ( ecm, currentPosition, currentPosition );
7474 }
7575
76+ void fixJointAtEndpoint ( gz::sim::EntityComponentManager & ecm, RoFICoMPosition position )
77+ {
78+ switch ( position )
79+ {
80+ case RoFICoMPosition::Extended:
81+ _jointData.joint .ResetPosition ( ecm, { _jointData.getMaxPosition () } );
82+ fixJoint ( ecm, _jointData.getMaxPosition () );
83+ break ;
84+ case RoFICoMPosition::Retracted:
85+ _jointData.joint .ResetPosition ( ecm, { _jointData.getMinPosition () } );
86+ fixJoint ( ecm, _jointData.getMinPosition () );
87+ break ;
88+ case RoFICoMPosition::Extending:
89+ case RoFICoMPosition::Retracting:
90+ assert ( false );
91+ break ;
92+ }
93+ }
94+
7695 void looseJoint ( gz::sim::EntityComponentManager & ecm )
7796 {
7897 _jointData.setPositionLimits ( ecm, _jointData.minPosition , _jointData.maxPosition );
@@ -98,7 +117,7 @@ class RoficomController
98117 break ;
99118 case RoFICoMPosition::Extended:
100119 case RoFICoMPosition::Retracted:
101- fixJoint ( ecm );
120+ fixJointAtEndpoint ( ecm, _position );
102121 break ;
103122 }
104123 }
@@ -162,9 +181,14 @@ class RoficomController
162181
163182 void setConnected ( gz::sim::EntityComponentManager & ecm, bool connected )
164183 {
165- if ( !connected
166- && ( _position == RoFICoMPosition::Extended
167- || _position == RoFICoMPosition::Retracted ) )
184+ if ( connected )
185+ {
186+ _position = RoFICoMPosition::Extended;
187+ fixJointAtEndpoint ( ecm, RoFICoMPosition::Extended );
188+ return ;
189+ }
190+
191+ if ( _position == RoFICoMPosition::Extended || _position == RoFICoMPosition::Retracted )
168192 {
169193 fixJoint ( ecm );
170194 }
0 commit comments