Robotics StackExchange | Archived questions

How to write file using model plugin?

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?

Asked by wangshanren on 2016-05-27 02:48:20 UTC

Comments

Answers

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();
}

Asked by Aiven92 on 2016-05-27 09:15:35 UTC

Comments