Home | Tutorials | Wiki | Issues
Ask Your Question
0

How to write file using model plugin?

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

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 -0600

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
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 452 times

Last updated: May 27 '16