Use the differential drive in a simulation
- I have created a project called TerrainLoader, in which I create a light source, a camera, a sky box, a plane and a LegoNXTTribot. The code for the tribot is as follows:
This all runs fine, the simulation loads with an error due to the drive partnership, which is expected.*** Partner enumeration during service startup failed. Partner Name:http://schemas.microsoft.com/robotics/2006/05/drive.html:LeftMotorCode Snippetvoid AddLegoNxtRobot(Vector3 position)
{
LegoNXTTribot robotBaseEntity = CreateLegoNxtMotorBase(ref position);
// Finaly insert the motor base and its two children
// to the simulation
SimulationEngine.GlobalInstancePort.Insert(robotBaseEntity);
robot = robotBaseEntity;
}private LegoNXTTribot CreateLegoNxtMotorBase(ref Vector3 position)
{
// use supplied entity that creates a motor base
// with 2 active wheels and one caster
LegoNXTTribot robotBaseEntity = new LegoNXTTribot(position);
// specify mesh.
robotBaseEntity.State.Assets.Mesh = "LegoNXTTribot.bos";
robotBaseEntity.WheelMesh = "LegoNXTTribotWheel.bos";
// the name below must match manifest
robotBaseEntity.State.Name = "LegoNXTMotorBase";
// Start simulated arcos motor service
CreateService(
Microsoft.Robotics.Services.Drive.Proxy.Contract.Identifier,
Microsoft.Robotics.Simulation.Partners.CreateEntityPartner(
"http://localhost/" + robotBaseEntity.State.Name)
);
return robotBaseEntity;}
Then I created a project called Actuator, which makes use of ONLY a differential drive:Code Snippet[ServiceState()]
private ActuatorState _state = new ActuatorState();
[ServicePort("/actuator", AllowMultipleInstances=false)]
private ActuatorOperations _mainPort = new ActuatorOperations();
[Partner("Drive", Contract = drive.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExisting)]
drive.DriveOperations _drivePort = new drive.DriveOperations();public ActuatorService(DsspServiceCreationPort creationPort) :
base(creationPort)
{
}protected override void Start()
{
if (_state == null)
{
_state = new ActuatorState();
_state.RobotStatus = "Waiting for a command";
}
base.Start();
// Add service specific initialization here.
Activate(
Arbiter.Interleave(
new TeardownReceiverGroup(),
new ExclusiveReceiverGroup(),
new ConcurrentReceiverGroup()
)
);
SpawnIterator<double, double>(10.0, 1.0, driveRobotDistance);
}
private IEnumerator<ITask> driveRobotDistance(double distance, double power)
{
drive.DriveDistanceRequest driveRequest = new drive.DriveDistanceRequest(distance / 1000.0, power);
yield return Arbiter.Choice(
_drivePort.DriveDistance(driveRequest),
delegate(DefaultUpdateResponseType response) { },
delegate(Fault fault)
{
LogError(null, "Unable to drive robot", fault);
}
);
_state.RobotStatus = "Driving robot according to distance";
}
The only thing I added to state was a string parameter for information purposes.
Now I am trying to link these two projects, or at least Actuator to some kind of simulation. I tried in the manifest, but I am not sure how that is supposed to look.
Can anyone tell me how to get the Actuator project to work in a simulation? Please help me, I'm pretty desperate!
-Quintin
Answers
- Solved it. I should not have written the Simulation Engine, rather designed it in the VSE. I typed out my solution at:
RobotExodus
All Replies
Hi, did you try just adding the other project as a reference? Such as in SimulationTutorial4. SimulatedLBR3Arm.Y2006.M07.Proxy.dll is added as a reference to the main project (SimulationTutorial4). Several of the other service / sim tutorials use that approach.
If you have trouble getting that to work, could you package up your code+solution+data files and host it somewhere? I might have some time to check it out, I could likely get back to you with a fix by Monday evening or Tuesday perhaps.
- Solved it. I should not have written the Simulation Engine, rather designed it in the VSE. I typed out my solution at:
RobotExodus
- Thanks Mike, it turns out it was just a manifest issue. I was loading things in the wrong place and getting all sorts of wonderful errors. Thankfully this morning I just started toying around and on hindsight it is such an elegant solution.
I'm sorry I answered so abruptly in the forums, I didn't even see your posts. Thank you for your help. The people at Microsoft are definitely wonderful and friendly people in my opinion. Also the robotics framework is just simply amazing!
-Quintin


