Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gazebo/gazebo.hh>
- #include <gazebo/physics/physics.hh>
- #include <gazebo/common/common.hh>
- #include <iostream>
- using namespace std;
- int main(int _argc, char **_argv)
- {
- // setup Gazebo server
- if(gazebo::setupServer())
- {
- cout << "Gazebo server setup successful\n";
- }
- else
- {
- cout << "Gazebo server setup failed!\n";
- }
- gazebo::physics::WorldPtr world = gazebo::loadWorld("worlds/empty.world");
- world->Run(0);
- // Start the Gazebo GUI
- system("gzclient &");
- string cameraString = "<?xml version=\"1.0\" ?>\
- <sdf version=\"1.5\">\
- <model name=\"camera\">\
- <static>true</static>\
- <pose>4 -4 4 0 0.5 2.4</pose>\
- <link name=link>\
- <pose>0.05 0.05 0.05 0 0 0</pose>\
- <inertial>\
- <mass>0.1</mass>\
- </inertial>\
- <visual name=\"visual\">\
- <geometry>\
- <box>\
- <size>0.1 0.1 0.1</size>\
- </box>\
- </geometry>\
- </visual>\
- <sensor name=\"camera\" type=\"camera\">\
- <camera>\
- <horizontal_fov>1.047</horizontal_fov>\
- <image>\
- <width>1280</width>\
- <height>960</height>\
- </image>\
- <clip>\
- <near>0.1</near>\
- <far>100</far>\
- </clip>\
- <save enabled=\"true\">\
- <path>/tmp/gazebo_frames</path>\
- </save>\
- </camera>\
- <always_on>1</always_on>\
- <update_rate>50</update_rate>\
- <visualize>true</visualize>\
- </sensor>\
- </link>\
- </model>\
- </sdf>";
- // insert the camera
- world->SetPaused(true);
- int modelCountBefore = world->GetModelCount();
- world->InsertModelString(cameraString);
- world->SetPaused(false);
- int retry=0;
- while (world->GetModelCount() == modelCountBefore)
- {
- gazebo::common::Time::MSleep(100);
- retry++;
- if (retry>1000)
- break;
- }
- if(world->GetModelCount() == modelCountBefore+1)
- {
- cout << "Successfully inserted model.\n";
- }
- else
- {
- cout << "Failed inserting model\n";
- }
- cin.ignore();
- gazebo::shutdown();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement