Chaper 8 sample code
Hello,
I'm not sure but I believe there is a mistake in the sample code of chapter 8.
The generic arm service has a state member called Joints.
The corresponding ArmGetHandler is registered as concurrent but inside you are changing the Joint member of the state.
I thought that you may not alter the state inside a concurrent service method. Is this right or should I read the book again?
Delblanco
PS: involved code sections:
inside the service start method:
// Add the winform message handler to the interleave
MainPortInterleave.CombineWith(new Interleave(
new TeardownReceiverGroup(),
new ExclusiveReceiverGroup( //some exclusive receivers ),
new ConcurrentReceiverGroup
(
Arbiter.ReceiveWithIterator<armproxy.Subscribe>(tr ue, _armPort, SubscribeHandler),
Arbiter.ReceiveWithIterator<armproxy.GetEndEffecto rPose>(true, _armPort, GetEndEffectorHandler),
Arbiter.Receive<DsspDefaultLookup>(true, _armPort, DefaultLookupHandler),
Arbiter.ReceiveWithIterator<armproxy.Get>(true, _armPort, ArmGetHandler)
)
));
/// <summary>
/// Get Handler
/// </summary>
/// <param name="get"></param>
/// <returns></returns>
/// <remarks>Get handler for Generic Arm contract</remarks>
//[ServiceHandler(ServiceHandlerBehavior.Concurrent)]
public virtual IEnumerator<ITask> ArmGetHandler(armproxy.Get get)
{
// Update the state first with the current joint info
float baseAngle = 0, shoulder = 0, elbow = 0, wrist = 0;
float rotate = 0, gripper = 0;
if (_l6Arm != null)
{
// Get the target joint angles for all joints
// removed some irrelevant lines
// Put the values into the state
_state.Joints[0].State.Angular.DriveTargetOrientation = AngleToOrientationQuaternion(baseAngle);
_state.Joints[1].State.Angular.DriveTargetOrientation = AngleToOrientationQuaternion(shoulder);
_state.Joints[2].State.Angular.DriveTargetOrientation = AngleToOrientationQuaternion(elbow);
_state.Joints[3].State.Angular.DriveTargetOrientation = AngleToOrientationQuaternion(wrist);
_state.Joints[4].State.Angular.DriveTargetOrientation = AngleToOrientationQuaternion(rotate);
_state.Joints[5].State.Angular.DriveTargetOrientation = AngleToOrientationQuaternion(gripper);
}
// Return the state
get.ResponsePort.Post(_state);
yield break;
}
|