当前位置: 首页>>代码示例>>C++>>正文


C++ Cat::faceEast方法代码示例

本文整理汇总了C++中Cat::faceEast方法的典型用法代码示例。如果您正苦于以下问题:C++ Cat::faceEast方法的具体用法?C++ Cat::faceEast怎么用?C++ Cat::faceEast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cat的用法示例。


在下文中一共展示了Cat::faceEast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv) 
{
	// Initialize the cat robot with the correct position position

	ros::init(argc,argv,"Animal");
	std::string xPosArg = argv[1];
	std::string spacingArg = argv[2];
	double spacing = atof(spacingArg.c_str());
	double xPos = atof(xPosArg.c_str());
	cat = Cat(xPos, 21.500);

	// Create ros handler for this node
	ros::NodeHandle n;

	cat.robotNode_stage_pub = n.advertise<geometry_msgs::Twist>("cmd_vel",1000);

	cat.stageOdo_Sub = n.subscribe<nav_msgs::Odometry>("base_pose_ground_truth",1000,stage_callback);
	ros::Rate loop_rate(10); 

	//subscribe to laser for cats
	cat.baseScan_Sub = n.subscribe<sensor_msgs::LaserScan>("base_scan", 1000,callBackLaserScan);

	// Broadcast the node's status information for other to subscribe to.
	ros::Publisher pub=n.advertise<se306project::animal_status>("status",1000);
	se306project::animal_status status_msg;
	// 0 rotatiing to the side, 1 moving horizontally, 2 rotating to bnorth/south, 3 moving vertical, 4 stop
	while (ros::ok())
	{
		// Message to stage 
		if(cat.getObstacleStatus().compare("Obstacle nearby")!=0){
			cat.move();
		}
		// Give cat a small initial movement to fill in its GUI status
		if (initial) {
			cat.addMovement("forward_x",0.1,1);
		}
		initial = false;

		// Generate random number of seconds for cat to sleep between 50-100s
		double num = (rand() % 100) / 2;
		double time = 50 + num;

		if (cat.getMovementQueueSize() == 0) {
			cat.addMovement("forward_x", 0.1, (0.1 / time));
			cat.faceEast(1);
			cat.addMovement("forward_x",5,1);
			cat.faceWest(1);
			cat.addMovement("forward_x",-5,1);
		}

		// Add Cat variables to status message to be broadcast
		status_msg.status=status;
		status_msg.pos_x=cat.getX();
		status_msg.pos_y=cat.getY();
		status_msg.pos_theta=cat.getAng();
		status_msg.obstacle=cat.getObstacleStatus();
		// Publish status message
		pub.publish(status_msg);
		ros::spinOnce();
		loop_rate.sleep();
		// Determine status of cat
		cat.determineStatus();
		//if ( cat.getLin() == 0.01 ) {
		//	status = "Sleeping";
		//}
	}
	return 0;
}
开发者ID:gdsl,项目名称:SOFTENG-306-PROJECT-1,代码行数:68,代码来源:Cat.cpp


注:本文中的Cat::faceEast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。