My restaurant.cpp does not work?? Is there any cpp file which i can use for a p3at robot using p2os? [closed]

asked 2013-09-25 19:10:14 -0500

xrobox gravatar image

#include "ros/ros.h" #include "std_msgs/String.h" #include <string> #include <iostream> #include <../sound_play/sound_play.h> #include <unistd.h> #include <move_base_msgs movebaseaction.h=""> #include <actionlib client="" simple_action_client.h=""> #include <std_srvs empty.h=""> #include "std_msgs/Float64.h" #include <sstream>

typedef actionlib::SimpleActionClient<move_base_msgs::movebaseaction> MoveBaseClient;

using namespace std; string speech; string order; int state = 0; double tableX = 3.7313, tableY = 0.8048, tableW = 0.99999, tableZ = 0.00534; double homeX = 0.7707, homeY = 0.426, homeW = 0.0562, homeZ = 0.9984;

ros::Publisher right_shoulder; ros::Publisher right_elbow; ros::Publisher right_arm; ros::Publisher left_shoulder; ros::Publisher left_elbow; ros::Publisher left_arm; ros::Publisher pan_joint; ros::Publisher tilt_joint;

void chatterCallback(const std_msgs::String::ConstPtr& msg) { ROS_INFO("I heard: [%s]", msg->data.c_str()); speech = msg->data.c_str(); }

bool query() { ROS_INFO("Waiting for query"); while(ros::ok()) { if(speech.find("yes")!=string::npos) { ROS_INFO("Yes!"); return true; break; } else if(speech.find("no")!=string::npos) { ROS_INFO("NO!"); return false; break; } ros::spinOnce();

}

}

bool sfound(string command) { if(speech.find(command)!=string::npos) return true; else return false; }

void getOrder() { ROS_INFO("Waiting for order"); while(ros::ok()) {

    if((speech.find("coffee")!=string::npos)||(speech.find("cappuccino")!=string::npos)||(speech.find("mocca")!=string::npos)||(speech.find("milk")!=string::npos)||(speech.find("teh")!=string::npos)||(speech.find("expresso")!=string::npos)||(speech.find("juice")!=string::npos)||(speech.find("rice")!=string::npos)||(speech.find("tea")!=string::npos))
    {
                order = speech ;
        ROS_INFO("Order received");
                break;
    }
ros::spinOnce();


}

}

void sleepok(int t, ros::NodeHandle &nh) { if(nh.ok()) sleep(t); }

void clearpausespeech() { sleep(3); //sleepok(6,n); speech.clear(); speech = ""; ROS_INFO("SPEECH CLEARED"); }

void resetmotors() { std_msgs::Float64 zero; std_msgs::Float64 zero2; zero.data = 0 ; zero2.data = -0.5; right_shoulder.publish(zero); left_shoulder.publish(zero); pan_joint.publish(zero); tilt_joint.publish(zero); right_elbow.publish(zero); left_elbow.publish(zero); right_arm.publish(zero2); left_arm.publish(zero);

}

void wave() { std_msgs::Float64 hello; std_msgs::Float64 hello2; std_msgs::Float64 hello4; std_msgs::Float64 hello6; int i = 0;

hello.data = 2.0;
right_shoulder.publish(hello);
hello6.data = -2.0;
left_shoulder.publish(hello6);
sleep (1);

for(i=0;i<=3;i++){
hello2.data = 0;
right_elbow.publish(hello2);
left_elbow.publish(hello2);
usleep(500000);
hello2.data = -1.0;
right_elbow.publish(hello2);
hello4.data = 1.0;
left_elbow.publish(hello4);
usleep(500000);}

}

int main(int argc, char **argv) { ros::init(argc, argv, "listener"); ros::NodeHandle n; ros::Subscriber sub = n.subscribe("recognizer/output", 1000, chatterCallback); ros::ServiceClient stopspeech = n.serviceClient<std_srvs::empty>("recognizer/stop"); ros::ServiceClient startspeech = n.serviceClient<std_srvs::empty>("recognizer/start"); right_shoulder= n.advertise<std_msgs::float64>("/right_shoulder/command", 1.0); right_elbow = n.advertise<std_msgs::float64>("/right_elbow/command", 1.0); right_arm = n.advertise<std_msgs::float64>("/right_arm/command", 1.0); left_shoulder= n.advertise<std_msgs::float64>("/left_shoulder/command", 1.0); left_elbow = n.advertise<std_msgs::float64>("/left_elbow/command", 1.0); left_arm = n.advertise<std_msgs::float64>("/left_arm/command", 1.0); pan_joint = n.advertise<std_msgs::float64>("/pan_joint/command", 1.0); tilt_joint = n.advertise<std_msgs::float64>("/tilt_joint/command", 1.0);

std_srvs::Empty empty; ros::Rate r(10);

//tell the action client that we want to spin a thread by default MoveBaseClient ac("move_base ... (more)

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2016-08-08 00:33:43.193791

Comments

This cpp does not work on my p3at robot and i cant find the solution to it please help :D.

xrobox gravatar image xrobox  ( 2013-09-25 19:40:44 -0500 )edit
1

Please clean up your question so it is readable. Maybe posting it on Gist or pastebin is in order here. Also, make your question more specific: posting source code and just asking how to make it work is too vague and doesn't help anyone but you.

georgebrindeiro gravatar image georgebrindeiro  ( 2013-09-26 08:13:15 -0500 )edit