src/nodes/src/environment.cpp
// Creates a model (adapted from Max Kelly, from MTRN4230, 21T2, Lab09 Demo)
Creates a model (adapted from Max Kelly, from MTRN4230, 21T2, Lab09 Demo)
Creates a model ( adapted from Max Kelly from MTRN4230 21T2 Lab09 Demo )
bool Model::spawn_model(std::string model_name, std::string model_path, double x, double y) {
        geometry_msgs::Pose model_pose;
        model_pose.position.x = MODEL_ORIGIN_X + WORKSPACE_ORIGIN_X + x;
        model_pose.position.y = MODEL_ORIGIN_Y + WORKSPACE_ORIGIN_Y + y;
        model_pose.position.z = MODEL_ORIGIN_Z + 0.01;
        tf2::Quaternion quaternion;
        quaternion.setRPY(0,0,0);
        model_pose.orientation = tf2::toMsg(quaternion);
        ros::ServiceClient spawnModel = node_handle.serviceClient<gazebo_msgs::SpawnModel>("gazebo/spawn_sdf_model");
        spawnModel.waitForExistence();
        gazebo_msgs::SpawnModel srv;
        srv.request.model_name = model_name;
        std::ifstream ifs;
        ifs.open(model_path);
        std::stringstream buffer;
        buffer << ifs.rdbuf();
        srv.request.model_xml = buffer.str();
        srv.request.initial_pose = model_pose;
        srv.request.robot_namespace = "/";
        srv.request.reference_frame = "world";
        spawnModel.call(srv);
        return srv.response.success;
    }
bool Model :: spawn_model ( std :: string model_name , std :: string model_path , double x , double y ) { geometry_msgs :: Pose model_pose ; model_pose . position . x = MODEL_ORIGIN_X + WORKSPACE_ORIGIN_X + x ; model_pose . position . y = MODEL_ORIGIN_Y + WORKSPACE_ORIGIN_Y + y ; model_pose . position . z = MODEL_ORIGIN_Z + 0.01 ; tf2 :: Quaternion quaternion ; quaternion . setRPY ( 0 , 0 , 0 ) ; model_pose . orientation = tf2 :: toMsg ( quaternion ) ; ros :: ServiceClient spawnModel = node_handle . serviceClient < gazebo_msgs :: SpawnModel > ( " " ) ; spawnModel . waitForExistence ( ) ; gazebo_msgs :: SpawnModel srv ; srv . request . model_name = model_name ; std :: ifstream ifs ; ifs . open ( model_path ) ; std :: stringstream buffer ; buffer << ifs . rdbuf ( ) ; srv . request . model_xml = buffer . str ( ) ; srv . request . initial_pose = model_pose ; srv . request . robot_namespace = " " ; srv . request . reference_frame = " " ; spawnModel . call ( srv ) ; return srv . response . success ; }
Creates a model (adapted from Max Kelly, from MTRN4230, 21T2, Lab09 Demo)
Creates a model ( adapted from Max Kelly from MTRN4230 21T2 Lab09 Demo )
// Convert the position of the model into geometry_msgs // Set the orientation of the model (0,0,0) // Spawns the model