Command To Relocate (Move) Robot In MobileSim
From MobileRobots Research and Academic Customer Support
There is a command that moves a robot to a new location in MobileSim (as if you had dragged the robot to the new location): SIM_SET_POSE (#224). ARIA does not yet (as of version 2.5) have a function to do this, you must construct an ArRobotPacket object and send it on the robot device connection.
The parameters are 4-byte integers for X, Y and Theta. The packet's argument type byte is ignored. Here is an example of how to send this command in ARIA, where 'robot' is an ArRobot object, and 'x', 'y' and 'th' are int variables containing desired position in milimeters and degrees (you can use ArMath::roundInt() if you need to round a double or float to an integer).
When writing the packet to the robot connection from a thread other than the ArRobot run thread (started with runAsync() or run()), then you must lock and unlock the ArRobot object. (Code invoked via an ArRobot task callback functor, such as a user task or sensor interpretation task, is run in the same thread, so do not use lock or unlock there.)
/* 'robot' is a pointer to an ArRobot object. x, y and th are float, double or int variables. */ ArRobotPacket pkt; pkt.setID(ArCommands::SIM_SET_POSE); pkt.uByteToBuf(0); // argument type: ignored. pkt.byte4ToBuf((ArTypes::Byte4)x); pkt.byte4ToBuf((ArTypes::Byte4)y); pkt.byte4ToBuf((ArTypes::Byte4)th); pkt.finalizePacket(); robot->lock(); // Omit this if in an ArRobot task callback (e.g. user task or sensor interpretation task) robot->getDeviceConnection()->writePacket(&pkt); robot->unlock(); // Omit this if in an ArRobot task callback (e.g. user task or sensor interpretation task)
The robot odometry is not changed.
You can use similar code in Java:
/* Java code. 'robot' is a reference to an ArRobot object. */
...
ArRobotPacket pkt = new ArRobotPacket();
pkt.setID((short)224);
pkt.uByteToBuf((short)0); // argument type: ignored.
pkt.byte4ToBuf((int)x);
pkt.byte4ToBuf((int)y);
pkt.byte4ToBuf((int)th);
pkt.finalizePacket();
robot.lock(); // Omit this if in a robot task callback (e.g. user task or sensor interpretation task)
pkt.log();
if(robot.getDeviceConnection().writePacket(pkt) > 0)
System.out.println("Write was OK");
else
System.out.println("Error writing");
robot.unlock(); // Omit this if in a robot task callback (e.g. user task or sensor interpretation task)
delete pkt;
