本文整理汇总了C++中ArRobot::getPose方法的典型用法代码示例。如果您正苦于以下问题:C++ ArRobot::getPose方法的具体用法?C++ ArRobot::getPose怎么用?C++ ArRobot::getPose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArRobot
的用法示例。
在下文中一共展示了ArRobot::getPose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setState
void TakeBlockToWall::setState(State state)
{
myState = state;
myNewState = true;
myStateStartTime.setToNow();
myStateStartPos = myRobot->getPose();
}
示例2: basic_turn
void basic_turn(int turnAngal)
{
// ArTime start;
// G_PTZHandler->reset();
//ArUtil::sleep(500);
//G_PTZHandler->tiltRel(-10);
//CameraMoveCount=0;
//robot.lock();
double robotHeading = robot.getPose().getTh();
robotHeading += turnAngal;
double robotCurrentX = robot.getPose().getX() ;
double robotCurrentY = robot.getPose().getY();
G_PathPlanning->pathPlanToPose(ArPose(robotCurrentX, robotCurrentY , robotHeading),true,true);
while(G_PathPlanning->getState() != ArPathPlanningTask::REACHED_GOAL );
//robot.setHeading(robot.getTh()+turnAngal);
// robot.unlock();
//start.setToNow();
//while (1)
//{
// robot.lock();
// if (robot.isHeadingDone())
// {
// printf(" Finished turn\n");
//
// ArUtil::sleep(50);
// cout << " current heading: " << " " << robot.getTh()<<endl;
// robot.unlock();
// break;
// }
// if (start.mSecSince() > 5000)
// {
// printf(" Turn timed out\n");
//
// cout << " current heading: " << " " << robot.getTh()<<endl;
// robot.unlock();
// break;
// }
// robot.unlock();
// ArUtil::sleep(10);
//}
}
示例3: S_RobotMotion
/*****************************************************************
** Robot Search Subroutine
******************************************************************/
void S_RobotMotion( ArServerClient *serverclient, ArNetPacket *socket)
{
G_PTZHandler->reset();
ArUtil::sleep(500);
G_PTZHandler->tiltRel(-10);
double robotHeading=0;
double robotDstX = robot.getPose().getX();
double robotDstY = robot.getPose().getY();
//---------Generate the next motion by random numbers------------
cout << "-------- Generate the next motion by random numbers --------" <<endl;
srand( time( NULL ) );
switch(rand()%4)
{
case 0: //¡û
robotDstY += 1000;
robotHeading = 90;
break;
case 1: //¡ü
robotDstX += 1000;
robotHeading = 0;
break;
case 2: //¡ú
robotDstY -= 1000;
robotHeading = -90;
break;
case 3: //¡ý
robotDstX -= 1000;
robotHeading = 180;
break;
}
G_PathPlanning->pathPlanToPose(ArPose(robotDstX, robotDstY, robotHeading), true,true);
cout << "RobotMotion is processing..." <<endl;
while(G_PathPlanning->getState() != ArPathPlanningTask::REACHED_GOAL )
{
if (G_PathPlanning->getState() == ArPathPlanningTask::ABORTED_PATHPLAN) { G_PathPlanning->cancelPathPlan();break;}
else if(G_PathPlanning->getState() == ArPathPlanningTask::FAILED_PLAN) {G_PathPlanning->pathPlanToPose(ArPose(-300,-100,0),true,true);}
}
serverclient->sendPacketTcp(socket);
//-------------------------------------------------------------------------------------------------------
}
示例4: showMenu
void showMenu(){
ArLog::log(ArLog::Normal ,"Posicion actual robot:\n");
robot->getPose().log();
cout << "Press the key for your option:" << endl << endl;
cout << " flecha arriba : avanzar" << endl;
cout << " flecha abajo : retroceder" << endl;
cout << " flecha izq / drch : girar" << endl;
cout << " p : start" << endl;
cout << " s : stop" << endl;
cout << " t : test parado" << endl;
cout << " w : guardar trayectoria" << endl;
cout << " g : guardar Medidas" << endl;
cout << " c : guardar Medidas continuamente" << endl;
cout << " x : Quit" << endl;
}
示例5: main
int main(int argc, char **argv)
{
std::string str;
int ret;
int dist;
ArTime start;
ArPose startPose;
bool vel2 = false;
// connection to the robot
ArSerialConnection con;
// the robot
ArRobot robot;
// the connection handler from above
ConnHandler ch(&robot);
// init area with a dedicated signal handling thread
Aria::init(Aria::SIGHANDLE_THREAD);
if (argc != 2 || (dist = atoi(argv[1])) == 0)
{
printf("Usage: %s <distInMM>\n", argv[0]);
exit(0);
}
if (dist < 1000)
{
printf("You must go at least a meter\n");
exit(0);
}
// open the connection with the defaults, exit if failed
if ((ret = con.open()) != 0)
{
str = con.getOpenMessage(ret);
printf("Open failed: %s\n", str.c_str());
Aria::shutdown();
return 1;
}
// set the robots connection
robot.setDeviceConnection(&con);
// try to connect, if we fail, the connection handler should bail
if (!robot.blockingConnect())
{
// this should have been taken care of by the connection handler
// but just in case
printf(
"asyncConnect failed because robot is not running in its own thread.\n");
Aria::shutdown();
return 1;
}
// run the robot in its own thread, so it gets and processes packets and such
robot.runAsync(false);
// just a big long set of printfs, direct motion commands and sleeps,
// it should be self-explanatory
robot.lock();
/*
robot.setAbsoluteMaxTransVel(2000);
robot.setTransVelMax(2000);
robot.setTransAccel(1000);
robot.setTransDecel(1000);
robot.comInt(82, 30); // rotkp
robot.comInt(83, 200); // rotkv
robot.comInt(84, 0); // rotki
robot.comInt(85, 30); // transkp
robot.comInt(86, 450); // transkv
robot.comInt(87, 4); // transki
*/
printf("Driving %d mm (going full speed for that far minus a meter then stopping)\n", dist);
if (vel2)
robot.setVel2(2200, 2200);
else
robot.setVel(2200);
robot.unlock();
start.setToNow();
startPose = robot.getPose();
while (1)
{
robot.lock();
printf("\r vel: %.0f x: %.0f y: %.0f: dist: %.0f heading: %.2f",
robot.getVel(), robot.getX(), robot.getY(),
startPose.findDistanceTo(robot.getPose()),
robot.getTh());
if (startPose.findDistanceTo(robot.getPose()) > abs(dist) - 1000)
{
printf("\nFinished distance\n");
robot.setVel(0);
robot.unlock();
break;
}
if (start.mSecSince() > 10000)
{
printf("\nDistance timed out\n");
robot.setVel(0);
robot.unlock();
break;
}
//.........这里部分代码省略.........
示例6:
void RosAriaNode::Mas1ToSla_cb( const geometry_msgs::PointStampedConstPtr &msg)
{
// Master 1 Position
Vm1 = msg->point.x;
Xm1 = Xm1 + Vm1;
// Master force
Fk1 = msg->point.y;
// Master 1 Positive Energy
mst1_slv_cmd_P = msg->point.z;
Xsd = Scale *(alpha*Xm1 + (1-alpha)*Xm2);// design position
Xsprv = Xs;
Position = robot->getPose();
Xs = Position.getX();
delta = Xs - Xsprv;
Vs = PosController.compute(Xsd,Xs);
// Fs - Sum
Fs = K_force*(Xsd - Xs);
Fs1 = alpha*Fs;
Fs2 = (1-alpha)*Fs;
/*
* Master 1 - Slave Channel
*/
// Calculate Negative Energy and dissipate Active energy
if (Vm1*Fs1>0)
{
mst1_slv_cmd_N -=Vm1*Fs1;
}
else
{
//Do nothing
}
// PC:
if (mst1_slv_cmd_N+mst1_slv_cmd_P<0)
{
mst1_slv_cmd_N +=Vm1*Fs1; // backward 1 step
Xm1 = Xm1 - Vm1; // backward 1 step
// Modify Vm1
if (Fs1*Fs1>0)
Vm1 = (mst1_slv_cmd_N+mst1_slv_cmd_P)/Fs1;
else
Vm1 = 0;
//Update
Xm1 = Xm1 + Vm1;
Xsd = Scale *(alpha*Xm1 + (1-alpha)*Xm2);// design position
Vs = PosController.compute(Xsd,Xs);
// Modify Fs ????
mst1_slv_cmd_N -=Vm1*Fs1;
}
/*
* Slave - Master 1 Channel
*/
// Calculate Positive Energy
if (Fk1*Vs>0)
{
//sla_mst1_cmd_P += Fk1*Vs;
sla_mst1_cmd_P += Fk1*delta;
}
else
{
//Do nothing
}
/*
* Master 2 - Slave Channel
*/
// Calculate Negative Energy and dissipate Active energy
if (Vm2*Fs2>0)
{
mst2_slv_cmd_N -=Vm2*Fs2;
}
else
{
//Do nothing
}
// PC:
if (mst2_slv_cmd_N+mst2_slv_cmd_P<0)
{
mst2_slv_cmd_N +=Vm2*Fs2; // backward 1 step
Xm2 = Xm2 - Vm2; // backward 1 step
// Modify Vm1
if (Fs2*Fs2>0)
Vm2 = (mst2_slv_cmd_N+mst2_slv_cmd_P)/Fs2;
else
Vm2 = 0;
//Update
Xm2 = Xm2 + Vm2;
Xsd = Scale *(alpha*Xm1 + (1-alpha)*Xm2);// design position
Vs = PosController.compute(Xsd,Xs);
//.........这里部分代码省略.........
示例7: handler
//.........这里部分代码省略.........
if (myPickUp->getState() == PickUp::STATE_FAILED)
{
printf("###### PickUpBlock: failed\n");
setState(STATE_BACKUP);
//handler();
return;
}
else if (myPickUp->getState() == PickUp::STATE_SUCCEEDED)
{
printf("###### PickUpBlock: successful\n");
setState(STATE_PICKUP_BACKUP);
//handler();
return;
}
break;
case STATE_BACKUP:
if (myNewState)
{
myNewState = false;
myRobot->move(BACKUP_DIST * .75);
myAcquire->deactivate();
myPickUp->deactivate();
myDriveTo->deactivate();
myDropOff->deactivate();
myTableLimiter->deactivate();
}
if (myRobot->isLeftMotorStalled() || myRobot->isRightMotorStalled())
{
printf("###### Backup: Failed, going forwards\n");
myRobot->clearDirectMotion();
setState(STATE_FORWARD);
}
if (myStateStartTime.mSecSince() > BACKUP_TIME ||
myStateStartPos.findDistanceTo(myRobot->getPose()) > BACKUP_DIST * .95 * .75)
{
printf("###### Backup: Succeeded\n");
myRobot->clearDirectMotion();
setState(STATE_ACQUIRE_BLOCK2);
//handler();
return;
}
break;
case STATE_FORWARD:
if (myNewState)
{
myNewState = false;
myRobot->move(-BACKUP_DIST * .75);
myAcquire->deactivate();
myPickUp->deactivate();
myDriveTo->deactivate();
myDropOff->deactivate();
myTableLimiter->deactivate();
}
if (myRobot->isLeftMotorStalled() || myRobot->isRightMotorStalled())
{
printf("###### Forward: Failed\n");
myRobot->clearDirectMotion();
setState(STATE_FAILED);
}
if (myStateStartTime.mSecSince() > BACKUP_TIME ||
myStateStartPos.findDistanceTo(myRobot->getPose()) >
ArMath::fabs(BACKUP_DIST * .95 * .75))
{
printf("###### Forward: Succeeded\n");
myRobot->clearDirectMotion();
setState(STATE_ACQUIRE_BLOCK2);
示例8: S_TargetApproach
void S_TargetApproach( ArServerClient *serverclient, ArNetPacket *socket)
{
//Important: to halt current movement of camera, making the reading curret.
G_PTZHandler->haltPanTilt();
cout << "The last step: TargetApproach!" <<endl;
//G_PathPlanning->setCollisionRange(1000);
//G_PathPlanning->setFrontClearance(40);
//G_PathPlanning->setGoalDistanceTolerance(2500);
double camAngle = -1 * G_PTZHandler->getPan();
double robotHeading = robot.getPose().getTh();
double robotCurrentX = robot.getPose().getX() ;
double robotCurrentY = robot.getPose().getY();
double angle = 0.0;
double distance =0.0;
double targetX, targetY;
int disThreshold = 500;
//test mode
// G_PTZHandler->panRel(-30);
//G_PathPlanning->setFrontClearance(40);
//G_PathPlanning->setObsThreshold(1);
cout << "--------------Path Planning Information--------------------" <<endl;
cout << "SafeCollisionRange = " << G_PathPlanning->getSafeCollisionRange() << endl;
cout << "FrontClearance = " << G_PathPlanning->getFrontClearance() << endl
<< "GoalDistanceTolerance = " << G_PathPlanning->getGoalDistanceTolerance() << endl
<< "setGoalOccupiedFailDistance = " << G_PathPlanning->getGoalOccupiedFailDistance() << endl
<< "getObsThreshold = " << G_PathPlanning->getObsThreshold() <<endl
<< "getLocalPathFailDistance = " << G_PathPlanning->getLocalPathFailDistance() << endl;
//getCurrentGoal
//--------------- Set up the laser range device to read the distance from the target -----------------------------
// for(int i =0; i< 20;i++)
//sick.currentReadingPolar(robotHeading+ camAngle -2.5, robotHeading+ camAngle +2.5, &angle);
//Begin:
sick.lockDevice();
//if (distance == 0 || distance>disThreshold)
distance = sick.currentReadingPolar(/*robotHeading+*/ camAngle -2.5, /*robotHeading+*/ camAngle +2.5, &angle)-disThreshold;
//double distance = sick.currentReadingPolar(89, 90, &angle);
cout << "The closest reading is " << distance << " at " << angle << " degree , " << "disThreshold : " <<disThreshold << " " << robotHeading << " " << camAngle<< endl;
sick.unlockDevice();
//----------------------------------------------------------------------------------------------------------------
//basic_turn(camAngle);
cout << "Camera Angle is " << camAngle << endl;
cout << "before calculation, check originalX, originalY " << robotCurrentX << " " << robotCurrentY << " robotHeading is " << robotHeading << endl<<endl;
coordinateCalculation(robotCurrentX,robotCurrentY,&targetX,&targetY,camAngle,robotHeading,distance);
//
//cout << "before movement, check targetX, target Y" << targetX << " " << targetY << "robotHeading is "<< robotHeading << endl << endl;
cout << "targetX : " <<targetX << " targetY" <<targetY;
G_PathPlanning->pathPlanToPose(ArPose(targetX,targetY,camAngle),true,true);
cout << "RobotMotion is processing..." <<endl;
G_PTZHandler->reset();
ArUtil::sleep(200);
G_PTZHandler->tiltRel(-10);
while(G_PathPlanning->getState() != ArPathPlanningTask::REACHED_GOAL )
{
if (G_PathPlanning->getState() == ArPathPlanningTask::FAILED_MOVE)
{
G_PathPlanning->cancelPathPlan();cout << "x " << robot.getPose().getX()<< " y " <<robot.getPose().getY() <<endl; break;
}
else if(G_PathPlanning->getState() == ArPathPlanningTask::FAILED_PLAN)
{
// getchar();
//getchar();
//getchar();
// getchar();
// disThreshold+=50;
//
// goto Begin;
}
}
//serverclient->sendPacketTcp(socket);
ArUtil::sleep(3000);
cout << "RobotMotion is heading home..." <<endl;
G_PathPlanning->pathPlanToPose(ArPose(0,0,0),true,true);
while(G_PathPlanning->getState() != ArPathPlanningTask::REACHED_GOAL )
{
//cout << G_PathPlanning->getState() <<endl;
//.........这里部分代码省略.........
示例9: publish
void RosAriaNode::publish()
{
// Note, this is called via SensorInterpTask callback (myPublishCB, named "ROSPublishingTask"). ArRobot object 'robot' sholud not be locked or unlocked.
pos = robot->getPose();
tf::poseTFToMsg(tf::Transform(tf::createQuaternionFromYaw(pos.getTh()*M_PI/180), tf::Vector3(pos.getX()/1000,
pos.getY()/1000, 0)), position.pose.pose); //Aria returns pose in mm.
position.twist.twist.linear.x = robot->getVel()/1000; //Aria returns velocity in mm/s.
position.twist.twist.linear.y = robot->getLatVel()/1000.0;
position.twist.twist.angular.z = robot->getRotVel()*M_PI/180;
position.header.frame_id = frame_id_odom;
position.child_frame_id = frame_id_base_link;
position.header.stamp = ros::Time::now();
pose_pub.publish(position);
ROS_DEBUG("RosAria: publish: (time %f) pose x: %f, y: %f, angle: %f; linear vel x: %f, y: %f; angular vel z: %f",
position.header.stamp.toSec(),
(double)position.pose.pose.position.x,
(double)position.pose.pose.position.y,
(double)position.pose.pose.orientation.w,
(double) position.twist.twist.linear.x,
(double) position.twist.twist.linear.y,
(double) position.twist.twist.angular.z
);
// publishing transform odom->base_link
odom_trans.header.stamp = ros::Time::now();
odom_trans.header.frame_id = frame_id_odom;
odom_trans.child_frame_id = frame_id_base_link;
odom_trans.transform.translation.x = pos.getX()/1000;
odom_trans.transform.translation.y = pos.getY()/1000;
odom_trans.transform.translation.z = 0.0;
odom_trans.transform.rotation = tf::createQuaternionMsgFromYaw(pos.getTh()*M_PI/180);
odom_broadcaster.sendTransform(odom_trans);
// getStallValue returns 2 bytes with stall bit and bumper bits, packed as (00 00 FrontBumpers RearBumpers)
int stall = robot->getStallValue();
unsigned char front_bumpers = (unsigned char)(stall >> 8);
unsigned char rear_bumpers = (unsigned char)(stall);
bumpers.header.frame_id = frame_id_bumper;
bumpers.header.stamp = ros::Time::now();
std::stringstream bumper_info(std::stringstream::out);
// Bit 0 is for stall, next bits are for bumpers (leftmost is LSB)
for (unsigned int i=0; i<robot->getNumFrontBumpers(); i++)
{
bumpers.front_bumpers[i] = (front_bumpers & (1 << (i+1))) == 0 ? 0 : 1;
bumper_info << " " << (front_bumpers & (1 << (i+1)));
}
ROS_DEBUG("RosAria: Front bumpers:%s", bumper_info.str().c_str());
bumper_info.str("");
// Rear bumpers have reverse order (rightmost is LSB)
unsigned int numRearBumpers = robot->getNumRearBumpers();
for (unsigned int i=0; i<numRearBumpers; i++)
{
bumpers.rear_bumpers[i] = (rear_bumpers & (1 << (numRearBumpers-i))) == 0 ? 0 : 1;
bumper_info << " " << (rear_bumpers & (1 << (numRearBumpers-i)));
}
ROS_DEBUG("RosAria: Rear bumpers:%s", bumper_info.str().c_str());
bumpers_pub.publish(bumpers);
//Publish battery information
// TODO: Decide if BatteryVoltageNow (normalized to (0,12)V) is a better option
std_msgs::Float64 batteryVoltage;
batteryVoltage.data = robot->getRealBatteryVoltageNow();
voltage_pub.publish(batteryVoltage);
if(robot->haveStateOfCharge())
{
std_msgs::Float32 soc;
soc.data = robot->getStateOfCharge()/100.0;
state_of_charge_pub.publish(soc);
}
// publish recharge state if changed
char s = robot->getChargeState();
if(s != recharge_state.data)
{
ROS_INFO("RosAria: publishing new recharge state %d.", s);
recharge_state.data = s;
recharge_state_pub.publish(recharge_state);
}
// publish motors state if changed
bool e = robot->areMotorsEnabled();
if(e != motors_state.data || !published_motors_state)
{
ROS_INFO("RosAria: publishing new motors state %d.", e);
motors_state.data = e;
motors_state_pub.publish(motors_state);
published_motors_state = true;
}
// Publish sonar information, if enabled.
//.........这里部分代码省略.........
示例10: main
//.........这里部分代码省略.........
handlerMapping.addMappingEndCallback(actionLostPath.getEnableCB());
handlerMapping.addMappingEndCallback(actionLostRatioDrive.getEnableCB());
handlerMapping.addMappingEndCallback(actionLostWander.getEnableCB());
// don't let forbidden lines show up as obstacles while mapping
// (they'll just interfere with driving while mapping, and localization is off anyway)
handlerMapping.addMappingStartCallback(forbidden.getDisableCB());
// let forbidden lines show up as obstacles again as usual after mapping
handlerMapping.addMappingEndCallback(forbidden.getEnableCB());
/*
// If we are on a simulator, move the robot back to its starting position,
// and reset its odometry.
// This will allow localizeRobotAtHomeBlocking() below will (probably) work (it
// tries current odometry (which will be 0,0,0) and all the map
// home points.
// (Ignored by a real robot)
//robot.com(ArCommands::SIM_RESET);
*/
// create a pose storage class, this will let the program keep track
// of where the robot is between runs... after we try and restore
// from this file it will start saving the robot's pose into the
// file
ArPoseStorage poseStorage(&robot);
/// if we could restore the pose from then set the sim there (this
/// won't do anything to the real robot)... if we couldn't restore
/// the pose then just reset the position of the robot (which again
/// won't do anything to the real robot)
if (poseStorage.restorePose("robotPose"))
serverLocHandler.setSimPose(robot.getPose());
else
robot.com(ArCommands::SIM_RESET);
/* File transfer services: */
#ifdef WIN32
// Not implemented for Windows yet.
ArLog::log(ArLog::Normal, "Note, file upload/download services are not implemented for Windows; not enabling them.");
#else
// This block will allow you to set up where you get and put files
// to/from, just comment them out if you don't want this to happen
// /*
ArServerFileLister fileLister(&server, fileDir);
ArServerFileToClient fileToClient(&server, fileDir);
ArServerFileFromClient fileFromClient(&server, fileDir, "/tmp");
ArServerDeleteFileOnServer deleteFileOnServer(&server, fileDir);
// */
#endif
/* Video image streaming, and camera controls (Requires SAVserver or ACTS) */
// Forward any video if either ACTS or SAV server are running.
// You can find out more about SAV and ACTS on our website
// http://robots.activmedia.com. ACTS is for color tracking and is
// a seperate product. SAV just does software A/V transmitting and is
// free to all our customers. Just run ACTS or SAV server before you
// start this program and this class here will forward video from the
// server to the client.
ArHybridForwarderVideo videoForwarder(&server, "localhost", 7070);
示例11: main
//.........这里部分代码省略.........
// Make Stop mode the default (If current mode deactivates without entering
// a new mode, then Stop Mode will be selected)
modeStop.addAsDefaultMode();
// TODO move up near where stop mode is created?
#ifdef ARNL_MAPPING
/* Services that allow the client to initiate scanning with the laser to
create maps in Mapper3 (So not possible with SONARNL): */
ArServerHandlerMapping handlerMapping(&server, &robot, firstLaser,
fileDir, "", true);
#ifdef ARNL_LASERLOC
// make laser localization stop while mapping
handlerMapping.addMappingStartCallback(
new ArFunctor1C<ArLocalizationTask, bool>
(&locTask, &ArLocalizationTask::setIdleFlag, true));
// and then make it start again when we're doine
handlerMapping.addMappingEndCallback(
new ArFunctor1C<ArLocalizationTask, bool>
(&locTask, &ArLocalizationTask::setIdleFlag, false));
#endif
#ifdef ARNL_GPSLOC
// Save GPS positions in the .2d scan log when making a map
handlerMapping.addLocationData("robotGPS",
gpsLocTask.getPoseInterpPositionCallback());
// add the starting latitude and longitude info to the .2d scan log
handlerMapping.addMappingStartCallback(
new ArFunctor1C<ArGPSLocalizationTask, ArServerHandlerMapping *>
(&gpsLocTask, &ArGPSLocalizationTask::addScanInfo,
&handlerMapping));
#endif
// Make it so our "lost" actions don't stop us while mapping
handlerMapping.addMappingStartCallback(actionLostRatioDrive.getDisableCB());
handlerMapping.addMappingStartCallback(actionLostWander.getDisableCB());
// And then let them make us stop as usual when done mapping
handlerMapping.addMappingEndCallback(actionLostRatioDrive.getEnableCB());
handlerMapping.addMappingEndCallback(actionLostWander.getEnableCB());
#endif // ARNL_MAPPING
/*
// If we are on a simulator, move the robot back to its starting position,
// and reset its odometry.
// This will allow localizeRobotAtHomeBlocking() below will (probably) work (it
// tries current odometry (which will be 0,0,0) and all the map
// home points.
// (Ignored by a real robot)
//robot.com(ArCommands::SIM_RESET);
*/
// create a pose storage class, this will let the program keep track
// of where the robot is between runs... after we try and restore
示例12: drive
void Joydrive::drive(void)
{
int trans, rot;
ArPose pose;
ArPose rpose;
ArTransform transform;
ArRangeDevice *dev;
ArSensorReading *son;
if (!myRobot->isConnected())
{
printf("Lost connection to the robot, exiting\n");
exit(0);
}
printf("\rx %6.1f y %6.1f th %6.1f",
myRobot->getX(), myRobot->getY(), myRobot->getTh());
fflush(stdout);
if (myJoyHandler.haveJoystick() && myJoyHandler.getButton(1))
{
if (ArMath::fabs(myRobot->getVel()) < 10.0)
myRobot->comInt(ArCommands::ENABLE, 1);
myJoyHandler.getAdjusted(&rot, &trans);
myRobot->setVel(trans);
myRobot->setRotVel(-rot);
}
else
{
myRobot->setVel(0);
myRobot->setRotVel(0);
}
if (myJoyHandler.haveJoystick() && myJoyHandler.getButton(2) &&
time(NULL) - myLastPress > 1)
{
myLastPress = time(NULL);
printf("\n");
switch (myTest)
{
case 1:
printf("Moving back to the origin.\n");
pose.setPose(0, 0, 0);
myRobot->moveTo(pose);
break;
case 2:
printf("Moving over a meter.\n");
pose.setPose(myRobot->getX() + 1000, myRobot->getY(), 0);
myRobot->moveTo(pose);
break;
case 3:
printf("Doing a transform test....\n");
printf("\nOrigin should be transformed to the robots coords.\n");
transform = myRobot->getToGlobalTransform();
pose.setPose(0, 0, 0);
pose = transform.doTransform(pose);
rpose = myRobot->getPose();
printf("Pos: ");
pose.log();
printf("Robot: ");
rpose.log();
if (pose.findDistanceTo(rpose) < .1)
printf("Success\n");
else
printf("#### FAILURE\n");
printf("\nRobot coords should be transformed to the origin.\n");
transform = myRobot->getToLocalTransform();
pose = myRobot->getPose();
pose = transform.doTransform(pose);
rpose.setPose(0, 0, 0);
printf("Pos: ");
pose.log();
printf("Robot: ");
rpose.log();
if (pose.findDistanceTo(rpose) < .1)
printf("Success\n");
else
printf("#### FAILURE\n");
break;
case 4:
printf("Doing a tranform test...\n");
printf("A point 1 meter to the -x from the robot (in local coords) should be transformed into global coordinates.\n");
transform = myRobot->getToGlobalTransform();
pose.setPose(-1000, 0, 0);
pose = transform.doTransform(pose);
rpose = myRobot->getPose();
printf("Pos: ");
pose.log();
printf("Robot: ");
rpose.log();
if (ArMath::fabs(pose.findDistanceTo(rpose) - 1000.0) < .1)
printf("Probable Success\n");
else
printf("#### FAILURE\n");
break;
case 5:
printf("Doing a transform test on range devices..\n");
printf("Moving the robot +4 meters x and +4 meters y and seeing if the moveTo will move the sonar readings along with it.\n");
dev = myRobot->findRangeDevice("sonar");
if (dev == NULL)
//.........这里部分代码省略.........
示例13: main
int main( int argc, char **argv ){
// parse our args and make sure they were all accounted for
ArSimpleConnector connector(&argc, argv);
ArRobot robot;
ArSick sick;
double dist, angle = 0;
// Allow for esc to release robot
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
printf("You may press escape to exit\n");
if( !connector.parseArgs() || argc > 1 ){
connector.logOptions();
exit(1);
}
// add the laser to the robot
robot.addRangeDevice(&sick);
// try to connect, if we fail exit
if( !connector.connectRobot(&robot) ){
printf("Could not connect to robot... exiting\n");
Aria::shutdown();
return 1;
}
// start the robot running, true so that if we lose connection the run stops
robot.runAsync(true);
// now set up the laser
connector.setupLaser(&sick);
sick.runAsync();
if( !sick.blockingConnect() ){
printf("Could not connect to SICK laser... exiting\n");
Aria::shutdown();
return 1;
}
robot.comInt(ArCommands::ENABLE, 1);
ArPose pose(0, -1000, 0);
robot.moveTo(pose);
ArPose prev_pose = robot.getPose();
double total_distance = 0;
printf("Connected\n");
ArUtil::sleep(1000);
PathLog log("../Data/reactive.dat");
int iterations_wo_movement = 0;
while( iterations_wo_movement < CONSECUTIVE_NON_MOTIONS ){
// Get updated measurement
sick.lockDevice();
dist = sick.currentReadingPolar(-90, 90, &angle);
sick.unlockDevice();
dist = (dist > 30000) ? 0 : dist - IDEAL_DISTANCE;
trackRobot(&robot, dist, angle);
ArUtil::sleep(500);
pose = robot.getPose();
log.write(pose);
total_distance += getDistance(prev_pose, pose);
prev_pose = pose;
// Determine if the robot is done tracking
isRobotTracking(&iterations_wo_movement, dist, angle);
}
ArUtil::sleep(1000);
log.close();
ofstream output;
output.open("../Data/reactive_dist.dat", ios::out | ios::trunc);
output << "Reactive 1 " << total_distance << endl;
output.close();
Aria::exit(0);
return 0;
}
示例14: publish
void RosAriaNode::publish()
{
// Note, this is called via SensorInterpTask callback (myPublishCB, named "ROSPublishingTask"). ArRobot object 'robot' sholud not be locked or unlocked.
pos = robot->getPose();
tf::poseTFToMsg(tf::Transform(tf::createQuaternionFromYaw(pos.getTh()*M_PI/180), tf::Vector3(pos.getX()/1000,
pos.getY()/1000, 0)), position.pose.pose); //Aria returns pose in mm.
position.twist.twist.linear.x = robot->getVel()/1000; //Aria returns velocity in mm/s.
position.twist.twist.angular.z = robot->getRotVel()*M_PI/180;
position.header.frame_id = frame_id_odom;
position.child_frame_id = frame_id_base_link;
position.header.stamp = ros::Time::now();
pose_pub.publish(position);
ROS_DEBUG("RosAria: publish: (time %f) pose x: %f, y: %f, angle: %f; linear vel x: %f, y: %f; angular vel z: %f",
position.header.stamp.toSec(),
(double)position.pose.pose.position.x,
(double)position.pose.pose.position.y,
(double)position.pose.pose.orientation.w,
(double) position.twist.twist.linear.x,
(double) position.twist.twist.linear.y,
(double) position.twist.twist.angular.z
);
// publishing transform odom->base_link
odom_trans.header.stamp = ros::Time::now();
odom_trans.header.frame_id = frame_id_odom;
odom_trans.child_frame_id = frame_id_base_link;
odom_trans.transform.translation.x = pos.getX()/1000;
odom_trans.transform.translation.y = pos.getY()/1000;
odom_trans.transform.translation.z = 0.0;
odom_trans.transform.rotation = tf::createQuaternionMsgFromYaw(pos.getTh()*M_PI/180);
odom_broadcaster.sendTransform(odom_trans);
// getStallValue returns 2 bytes with stall bit and bumper bits, packed as (00 00 FrontBumpers RearBumpers)
int stall = robot->getStallValue();
unsigned char front_bumpers = (unsigned char)(stall >> 8);
unsigned char rear_bumpers = (unsigned char)(stall);
bumpers.header.frame_id = frame_id_bumper;
bumpers.header.stamp = ros::Time::now();
std::stringstream bumper_info(std::stringstream::out);
// Bit 0 is for stall, next bits are for bumpers (leftmost is LSB)
for (unsigned int i=0; i<robot->getNumFrontBumpers(); i++)
{
bumpers.front_bumpers[i] = (front_bumpers & (1 << (i+1))) == 0 ? 0 : 1;
bumper_info << " " << (front_bumpers & (1 << (i+1)));
}
ROS_DEBUG("RosAria: Front bumpers:%s", bumper_info.str().c_str());
bumper_info.str("");
// Rear bumpers have reverse order (rightmost is LSB)
unsigned int numRearBumpers = robot->getNumRearBumpers();
for (unsigned int i=0; i<numRearBumpers; i++)
{
bumpers.rear_bumpers[i] = (rear_bumpers & (1 << (numRearBumpers-i))) == 0 ? 0 : 1;
bumper_info << " " << (rear_bumpers & (1 << (numRearBumpers-i)));
}
ROS_DEBUG("RosAria: Rear bumpers:%s", bumper_info.str().c_str());
bumpers_pub.publish(bumpers);
//Publish battery information
// TODO: Decide if BatteryVoltageNow (normalized to (0,12)V) is a better option
std_msgs::Float64 batteryVoltage;
batteryVoltage.data = robot->getRealBatteryVoltageNow();
voltage_pub.publish(batteryVoltage);
if(robot->haveStateOfCharge())
{
std_msgs::Float32 soc;
soc.data = robot->getStateOfCharge()/100.0;
state_of_charge_pub.publish(soc);
}
// publish recharge state if changed
char s = robot->getChargeState();
if(s != recharge_state.data)
{
ROS_INFO("RosAria: publishing new recharge state %d.", s);
recharge_state.data = s;
recharge_state_pub.publish(recharge_state);
}
// publish motors state if changed
bool e = robot->areMotorsEnabled();
if(e != motors_state.data || !published_motors_state)
{
ROS_INFO("RosAria: publishing new motors state %d.", e);
motors_state.data = e;
motors_state_pub.publish(motors_state);
published_motors_state = true;
}
if (robot->areSonarsEnabled())
{
//.........这里部分代码省略.........
示例15: readPosition
void readPosition(ArRobot& robot){
ArPose pose = robot.getPose();
fseek(G_pose_fd, SEEK_SET, 0);
fprintf(G_pose_fd, "x=%0.6f;y=%0.6f;th=%0.6f;\n", pose.getX(), pose.getY(), pose.getTh());
}