Programming help required regarding creating a function to call _hexapodEntity.MoveTo method
-
Wednesday, January 18, 2012 4:33 AM
Dear All,
I am working with the hexapod example of PROMRDS using MRDS and got stuck in a programming related issue.
The HexapodDifferentialDrive.cs contains a method _hexapodEntity.MoveTo to move the joints as given by the following code:
yield return Arbiter.Choice(_hexapodEntity.MoveTo(
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle, 2),
delegate(SuccessResult s) { },
ShowError);The above code produces one unique motion for the provided joint values. In order to generate a sequential(multiple) motion, I am re-writing the above code multiple times which has resulted in a large volume of code.
I have the following two concerns:
1) How can I execute this code in a loop? Enclosing the above code in for or while loop gives me error.
2) In order to create a function containing this code, what should be the format of the function?
Thanks,
Regards,
umar
All Replies
-
Friday, January 20, 2012 9:31 PMOwner
I don't see how you can reduce the volume of code. Even if you create your own wrapper, it will still have to be passed all of the joint angles so a call to your custom method will be nearly as long as the code snippet you gave.
1. It makes no difference if you do a yield return inside a for or a while. Are you doing this inside an Iterator? You cannot use yield return in a normal method.
2. You can create a method that returns an Arbiter.Choice and then call the method in a yield return. Note that yield return activates the Choice in this case. If you are created a walking routine you might only have a couple of different combinations of joint angles, so you could define a routine for each of them and not pass the joint angles to these methods (the angles can be internal to the methods).
Trevor
-
Saturday, January 21, 2012 7:07 AM
Thanks Trevor,
Your explanation helped a lot. Thanks for the prompt response.
I have created separate methods for pre-defined motions using the following format:
public IEnumerator<ITask> Step1()
{
yield return Arbiter.Choice(_hexapodEntity.MoveTo(
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle,
90, shoulderAngle, elbowAngle, 2),
delegate(SuccessResult s) { },
ShowError);}
In my main program I call the respective method using:
SpawnIterator(Step1);
Thanks,
Best regards,
Umar
-
Monday, January 23, 2012 1:51 AMOwner
Just be aware that SpawnIterator does not cause that particular thread to wait for the task to complete. In the simulator things happen very fast, so you might not notice. However, on a real robot you would have to be careful not to send the commands too quickly.
Trevor
-
Monday, January 23, 2012 4:46 AM
Thanks Trevor for the quick suggestion.
You have pointed out a crucial aspect regarding the SpawIterator.Let's suppose that I have multiple SpawIterator statements in my main program as the following:
SpawnIterator(Step1);
SpawnIterator(Step2);
SpawnIterator(Step3);
In such a situation, shouldn't Step2 come into effect after Step1 and similarly, Step3 after completing Step1 & Step2? If that's not the case then what should be the appropriate solution?
Thanks,
Umar
-
Friday, March 23, 2012 9:11 PMOwner
Internally the steps will be dispatched to threads and there is no guarantee that they will be executed in order. If you need activities to be serialized then combine them into one "Step"
- Proposed As Answer by Gershon ParentOwner Friday, March 30, 2012 1:06 AM
- Marked As Answer by Ashley Nathan FenielloMicrosoft Employee, Moderator Tuesday, April 10, 2012 6:09 PM

