Gazebo | Ignition | Community
Ask Your Question
0

How to write file using model plugin?

asked 2016-05-27 02:48:20 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Using coding as following:

public:

void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf) {
    this->model = _parent;
    this->updateConnection = event::Events::ConnectWorldUpdateBegin(
            boost::bind(&ModelPluginTutorial::OnUpdate, this, _1));     
    std::ofstream file("Angle.txt");
    for (int i = 0; i < N; i++) {
        file << position[i] << std::endl;
    }
    file.close();
}

However things turned out unexpected,there are no file generated.who can help me out of this problem?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-05-27 09:15:35 -0500

Aiven92 gravatar image

Use an absolute path to the file with parameters for open.

out.open("/home/username/.gazebo/models/legged_robot/out.dat",std::ios_base::out | std::ios_base::trunc);
if(!out.is_open()){
   gzerr << "Can't open log file\n";
}
...
~MobileBasePlugin(){
    out.close();
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-27 02:48:20 -0500

Seen: 587 times

Last updated: May 27 '16