Open ktiwari9 opened 9 years ago
Hi,
Thank you very much for your interest and your feedback.
I'm really not used with gazebo, so I'm afraid I cannot be of great help. However, I should say that this project is a "/work in progress/" and so I cannot guaranty, yet, it's functionnal. I did not really test it yet and I'm pretty sure frame of some joints are not correct for exemple. I will soon test it quite seriously and correct bugs related to the model. In this process, I will add some launch files much more complete, in order to test the model. You can then get inspired by those launch files for your code, I guess.
Again, I'm sorry I cannot be of great help on gazebo side. However, in case you missed something obvious, do you have any logs / output from gazebo you can send ? You said you cannot see the human, but did you get any error or output message ?
If you are interested, please keep watching the project, I will update soon.
Thanks, Renaud
Le 18/08/2015 04:40, Kshitij Tiwari a écrit :
Hi there, I am interested in adding a human in gazebo and so I am using your code. I cloned ur git repo into my workspace and I added a function like : void Husky::addHuman(){ ROSINFO("**/::executing add human ()"); // make the service call to spawn model ros::service::waitForService("gazebo/spawn_urdf_model"); gazebo_msgs::SpawnModel spawnModel; std::string urdf_filename = "human.urdf"; std::ifstream file("/home/toshiba/catkin_ws/src/gazebo_husky/human_model/urdf/human.urdf"); ROSDEBUG("loading file: %s , */******",urdf_filename.c_str()); // to check if URDF file was read correctly. std::string line;
|while(!file.eof()) // Parse the contents of the given urdf in a string { std::getline(file,line); model.request.model_xml+=line; } file.close();
geometry_msgs::Pose pose; pose.position.x = pose.position.y = 1; pose.position.z = 0; pose.orientation.w = 1.0; pose.orientation.x = pose.orientation.y = pose.orientation.z = 0; model.request.initial_pose = pose;
model.request.model_name="human_model"; model.request.reference_frame="world"; gazebo_spawnclt.call(model); //Call the service
ROS_INFO(" Finished loading human -------------------------------------"); |
}
Then I simply call this function in my main.cpp file but I do not see any human in gazebo. Am I missing something in my code/CmakeLists.txt/package.xml/launch file ? Please advise.
— Reply to this email directly or view it on GitHub https://github.com/RenaudViry/human_model/issues/1.
Hi Renaud, There are no bugs whatsoever in my code and the terminal. I can see the robot doing its random walk which it was supposed to do with or without the humans. So I have no clue what am I missing.
Ok, can you open an issue on github and add your sample code please ? I will have a look.
Thanks, Renaud
Le 18/08/2015 10:57, Kshitij Tiwari a écrit :
Hi Renaud, There are no bugs whatsoever in my code and the terminal. I can see the robot doing its random walk which it was supposed to do with or without the humans. So I have no clue what am I missing.
— Reply to this email directly or view it on GitHub https://github.com/RenaudViry/human_model/issues/1#issuecomment-132125076.
Want me to add my code here itself ?
Yep, the minimal functional one please. It's in order to reproduce the issue you have and try to solve it.
Le 18/08/2015 11:01, Kshitij Tiwari a écrit :
Want me to add my code here itself ?
— Reply to this email directly or view it on GitHub https://github.com/RenaudViry/human_model/issues/1#issuecomment-132125689.
So here is the source code
std::string model_name = "human_model";
Husky::Husky():n_(){
cmd_velpub = n_.advertise
laser_sub_ = n_.subscribe("scan", 10, &Husky::laserCallback, this);
odom_sub_ = n_.subscribe("odom", 10, &Husky::odomCallback, this);
gazebo_spawn_clt_= n_.serviceClient<gazebo_msgs::SpawnModel> ("/gazebo/spawn_urdf_model");
obstacle_ = false;
}
void Husky::laserCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
{
std::vector
//ROS_INFO("Smallest range is %lf", *range_it);
if(*range_it < min_range_) obstacle_ = true;
else obstacle_ = false;
}
void Husky::odomCallback(const navmsgs::Odometry::ConstPtr& msg) { x = msg->pose.pose.position.x; y = msg->pose.pose.position.y; yaw = tf::getYaw(msg->pose.pose.orientation); }
void Husky::setSpeed(double linear_speed, double angular_speed) { geometry_msgs::Twist msg; msg.linear.x = linear_speed; msg.angular.z = angular_speed; cmd_velpub.publish(msg); }
void Husky::setRangeLimit(double min_range) { minrange = min_range; }
Husky::~Husky(){}
void Husky::addHuman(){ // ROSINFO("****::executing add human ()"); // make the service call to spawn model ros::service::waitForService("gazebo/spawn_urdf_model"); gazebo_msgs::SpawnModel spawnModel; string urdf_filename = "human.urdf"; ifstream file("/home/toshiba/catkin_ws/src/human_model/urdf/human.urdf"); ROSDEBUG("loading file: %s , *****",urdf_filename.c_str()); // to check if URDF file was read correctly. string line;
while(!file.eof()) // Parse the contents of the given urdf in a string
{
getline(file,line);
model.request.model_xml+=line;
}
file.close();
geometry_msgs::Pose pose;
pose.position.x = pose.position.y = 1; pose.position.z = 0;
pose.orientation.w = 1.0; pose.orientation.x = pose.orientation.y = pose.orientation.z = 0;
model.request.initial_pose = pose;
model.request.model_name=model_name;
model.request.reference_frame="";
model.request.robot_namespace="";
gazebo_spawn_clt_.call(model); //Call the service
ROS_INFO("***************Added human to (%f, %f, %f).", pose.position.x, pose.position.y, pose.position.z);
// ROS_INFO(" Finished loading human -------------------------------------");
}
void Husky::respawn(){ gazebo_msgs::ModelState new_modelstate;
new_modelstate.model_name = model_name;
new_modelstate.reference_frame = "";
geometry_msgs::Pose new_pose;
new_pose.position.x = rand() % 20 - 10; new_pose.position.y = rand() % 20 - 10; new_pose.position.z = 0;
new_pose. orientation.w = 1.0; new_pose.orientation.x = new_pose.orientation.y = new_pose.orientation.z = 0;
new_modelstate.pose = new_pose;
respawner_pub_.publish(new_modelstate);
ROS_INFO("Respawned human to (%f, %f, %f).****************", new_pose.position.x, new_pose.position.y, new_pose.position.z);
}
Here is my main.cpp file
int main(int argc, char **argv) {
// ros::init (argc, argv, "gazebo_husky"); // Husky husky;
// ros::spin(); // return 0;
ros::init(argc, argv, "gazebo_husky");
ROS_INFO("Random walk example - Simple version");
ros::NodeHandle n;
ros::NodeHandle pn("~");
double min_x, max_x, min_y, max_y, min_range, max_linear_speed, max_angular_speed;
pn.param("min_x", min_x, -1.0);
pn.param("max_x", max_x, 1.0);
pn.param("min_y", min_y, -1.0);
pn.param("max_y", max_y, 1.0);
pn.param("min_range", min_range, 3.0);
pn.param("max_linear_speed", max_linear_speed, 0.2);
pn.param("max_angular_speed", max_angular_speed, 0.2);
ros::Duration(1.0).sleep();
Husky husky;
husky.setRangeLimit(min_range);
husky.addHuman();
double target_yaw = (double(rand()) / double(RAND_MAX)) * 2*M_PI - M_PI;
double a = 1;
ros::Rate r(10.0);
while(ros::ok())
{
// If there is an obstacle or if we are at the edge of the admissible area set a new direction
if(husky.obstacle() || husky.x() < min_x || husky.x() > max_x || husky.y() < min_y || husky.y() > max_y)
{
srand(time(NULL));
target_yaw = angles::normalize_angle(husky.yaw()+M_PI) + ((double(rand()) / double(RAND_MAX)) * M_PI/4 - M_PI/8);
}
husky.setSpeed(max_linear_speed, max_angular_speed*angles::shortest_angular_distance(husky.yaw(), target_yaw)*a);
//ROS_INFO("Linear %lf Angular %lf", max_linear_speed, max_angular_speed*angles::shortest_angular_distance(husky.yaw(), target_yaw)*a);
husky.respawn();
ros::spinOnce();
r.sleep();
}
return 0;
}
And here is my launch file
perhaps if you have all of this u can have exactly what I have. Random walking husky but no human for some reason. I am trying to fix this too but if we can work together would be quite nice :+1:
Yep, I agree, we better work together. Thanks for the files, I will have a look into it once I have corrected the file. Keep you updated.
Cheers mate. Looking forward to it.
I think we should first check if by using the command line like rosrun gazebo spawn_model -file pwd
/human.urdf -urdf -z 1 -model human_object we should see the human spawn in gazebo and we can be sure your urdf is fine then we can get to debugging my code.
Ok, I just made some test, looks like the model is absolutely not correct ! So I'm going to correct it first and then we can debug your code. I think I know where the problem comes from. I'll let you know once I have something functionnal.
Cheers.
Sweet. Thats some good news
Hi there, I am interested in adding a human in gazebo and so I am using your code. I cloned ur git repo into my workspace and I added a function like : void Husky::addHuman(){ ROSINFO("****::executing add human ()"); // make the service call to spawn model ros::service::waitForService("gazebo/spawn_urdf_model"); gazebo_msgs::SpawnModel spawnModel; std::string urdf_filename = "human.urdf"; std::ifstream file("/home/toshiba/catkin_ws/src/gazebo_husky/human_model/urdf/human.urdf"); ROSDEBUG("loading file: %s , *****",urdf_filename.c_str()); // to check if URDF file was read correctly. std::string line;
}
Then I simply call this function in my main.cpp file but I do not see any human in gazebo. Am I missing something in my code/CmakeLists.txt/package.xml/launch file ? Please advise.