neurali:gazebo_box_animato_source
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
neurali:gazebo_box_animato_source [2016/07/17 00:44] – [CMakeLists.txt] profpro | neurali:gazebo_box_animato_source [2020/06/08 22:20] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Codice sorgente box animato | ||
+ | Il codice è utilizzato in questo tutorial [[neurali: | ||
+ | |||
+ | Notare l' | ||
+ | |||
+ | ===== animated_box.cc ===== | ||
+ | |||
+ | <code cpp> | ||
+ | /* | ||
+ | * Copyright (C) 2012-2014 Open Source Robotics Foundation | ||
+ | * | ||
+ | * Licensed under the Apache License, Version 2.0 (the " | ||
+ | * you may not use this file except in compliance with the License. | ||
+ | * You may obtain a copy of the License at | ||
+ | * | ||
+ | | ||
+ | * | ||
+ | * Unless required by applicable law or agreed to in writing, software | ||
+ | * distributed under the License is distributed on an "AS IS" BASIS, | ||
+ | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
+ | * See the License for the specific language governing permissions and | ||
+ | * limitations under the License. | ||
+ | * | ||
+ | */ | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | namespace gazebo | ||
+ | { | ||
+ | class AnimatedBox : public ModelPlugin | ||
+ | { | ||
+ | public: void Load(physics:: | ||
+ | { | ||
+ | // Store the pointer to the model | ||
+ | this-> | ||
+ | |||
+ | // create the animation | ||
+ | gazebo:: | ||
+ | // name the animation " | ||
+ | // make it last 10 seconds, | ||
+ | // and set it on a repeat loop | ||
+ | new gazebo:: | ||
+ | |||
+ | gazebo:: | ||
+ | |||
+ | // set starting location of the box | ||
+ | key = anim-> | ||
+ | key-> | ||
+ | key-> | ||
+ | |||
+ | // set waypoint location after 2 seconds | ||
+ | key = anim-> | ||
+ | key-> | ||
+ | key-> | ||
+ | |||
+ | |||
+ | key = anim-> | ||
+ | key-> | ||
+ | key-> | ||
+ | |||
+ | |||
+ | key = anim-> | ||
+ | key-> | ||
+ | key-> | ||
+ | |||
+ | |||
+ | key = anim-> | ||
+ | key-> | ||
+ | key-> | ||
+ | |||
+ | // set final location equal to starting location | ||
+ | key = anim-> | ||
+ | key-> | ||
+ | key-> | ||
+ | |||
+ | // set the animation | ||
+ | _parent-> | ||
+ | } | ||
+ | |||
+ | // Pointer to the model | ||
+ | private: physics:: | ||
+ | |||
+ | // Pointer to the update event connection | ||
+ | private: event:: | ||
+ | }; | ||
+ | |||
+ | // Register this plugin with the simulator | ||
+ | GZ_REGISTER_MODEL_PLUGIN(AnimatedBox) | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== independent_listener.cc ===== | ||
+ | |||
+ | |||
+ | <code cpp> | ||
+ | /* | ||
+ | * Copyright (C) 2012-2014 Open Source Robotics Foundation | ||
+ | * | ||
+ | * Licensed under the Apache License, Version 2.0 (the " | ||
+ | * you may not use this file except in compliance with the License. | ||
+ | * You may obtain a copy of the License at | ||
+ | * | ||
+ | | ||
+ | * | ||
+ | * Unless required by applicable law or agreed to in writing, software | ||
+ | * distributed under the License is distributed on an "AS IS" BASIS, | ||
+ | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
+ | * See the License for the specific language governing permissions and | ||
+ | * limitations under the License. | ||
+ | * | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | |||
+ | ///////////////////////////////////////////////// | ||
+ | // Function is called every time a message is received. | ||
+ | void posesStampedCallback(ConstPosesStampedPtr & | ||
+ | { | ||
+ | std::cout << posesStamped-> | ||
+ | |||
+ | :: | ||
+ | :: | ||
+ | std::cout << "Read time: sec: " << sec << " nsec: " << nsec << std::endl; | ||
+ | |||
+ | for (int i =0; i < posesStamped-> | ||
+ | { | ||
+ | const :: | ||
+ | std::string name = pose.name(); | ||
+ | if (name == std:: | ||
+ | { | ||
+ | const :: | ||
+ | |||
+ | double x = position.x(); | ||
+ | double y = position.y(); | ||
+ | double z = position.z(); | ||
+ | |||
+ | std::cout << "Read position: x: " << x | ||
+ | << " y: " << y << " z: " << z << std::endl; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ///////////////////////////////////////////////// | ||
+ | int main(int _argc, char **_argv) | ||
+ | { | ||
+ | // Load gazebo | ||
+ | gazebo:: | ||
+ | |||
+ | // Create our node for communication | ||
+ | gazebo:: | ||
+ | node-> | ||
+ | |||
+ | // Listen to Gazebo pose info topic | ||
+ | gazebo:: | ||
+ | node-> | ||
+ | |||
+ | // Busy wait loop...replace with your own code as needed. | ||
+ | while (true) | ||
+ | gazebo:: | ||
+ | |||
+ | // Make sure to shut everything down. | ||
+ | gazebo:: | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== integrated_main.cc ===== | ||
+ | |||
+ | |||
+ | |||
+ | <code cpp> | ||
+ | /* | ||
+ | * Copyright (C) 2012-2014 Open Source Robotics Foundation | ||
+ | * | ||
+ | * Licensed under the Apache License, Version 2.0 (the " | ||
+ | * you may not use this file except in compliance with the License. | ||
+ | * You may obtain a copy of the License at | ||
+ | * | ||
+ | | ||
+ | * | ||
+ | * Unless required by applicable law or agreed to in writing, software | ||
+ | * distributed under the License is distributed on an "AS IS" BASIS, | ||
+ | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
+ | * See the License for the specific language governing permissions and | ||
+ | * limitations under the License. | ||
+ | * | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | |||
+ | ///////////////////////////////////////////////// | ||
+ | // Function is called every time a message is received. | ||
+ | void posesStampedCallback(ConstPosesStampedPtr & | ||
+ | { | ||
+ | std::cout << posesStamped-> | ||
+ | |||
+ | :: | ||
+ | :: | ||
+ | std::cout << "Read time: sec: " << sec << " nsec: " << nsec << std::endl; | ||
+ | |||
+ | for (int i =0; i < posesStamped-> | ||
+ | { | ||
+ | const :: | ||
+ | std::string name = pose.name(); | ||
+ | if (name == std:: | ||
+ | { | ||
+ | const :: | ||
+ | |||
+ | double x = position.x(); | ||
+ | double y = position.y(); | ||
+ | double z = position.z(); | ||
+ | |||
+ | std::cout << "Read position: x: " << x | ||
+ | << " y: " << y << " z: " << z << std::endl; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ///////////////////////////////////////////////// | ||
+ | int main(int _argc, char **_argv) | ||
+ | { | ||
+ | std::string str = " | ||
+ | if (_argc > 1) | ||
+ | { | ||
+ | str = _argv[1]; | ||
+ | } | ||
+ | |||
+ | // load gazebo server | ||
+ | gazebo:: | ||
+ | |||
+ | // Load a world | ||
+ | gazebo:: | ||
+ | |||
+ | // Create our node for communication | ||
+ | gazebo:: | ||
+ | node-> | ||
+ | |||
+ | // Listen to Gazebo pose information topic | ||
+ | gazebo:: | ||
+ | node-> | ||
+ | |||
+ | // Busy wait loop...replace with your own code as needed. | ||
+ | while (true) | ||
+ | { | ||
+ | // Run simulation for 100 steps. | ||
+ | gazebo:: | ||
+ | } | ||
+ | |||
+ | // Make sure to shut everything down. | ||
+ | gazebo:: | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ===== CMakeLists.txt ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | < | ||
+ | cmake_minimum_required(VERSION 2.8 FATAL_ERROR) | ||
+ | |||
+ | project(animated_box) | ||
+ | |||
+ | # Find packages | ||
+ | |||
+ | find_package(Boost REQUIRED COMPONENTS system) | ||
+ | include_directories(${Boost_INCLUDE_DIRS}) | ||
+ | link_directories(${Boost_LIBRARY_DIRS}) | ||
+ | |||
+ | |||
+ | find_package(Protobuf REQUIRED) | ||
+ | |||
+ | include (FindPkgConfig) | ||
+ | if (PKG_CONFIG_FOUND) | ||
+ | pkg_check_modules(GAZEBO gazebo) | ||
+ | endif() | ||
+ | |||
+ | |||
+ | # include appropriate directories | ||
+ | include_directories(${GAZEBO_INCLUDE_DIRS}) | ||
+ | link_directories(${GAZEBO_LIBRARY_DIRS}) | ||
+ | |||
+ | # Create libraries and executables | ||
+ | |||
+ | add_library(animated_box SHARED animated_box.cc) | ||
+ | target_link_libraries(animated_box ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES}) | ||
+ | |||
+ | add_executable(integrated_main integrated_main.cc) | ||
+ | target_link_libraries(integrated_main ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES} ${PROTOBUF_LIBRARIES} pthread) | ||
+ | |||
+ | |||
+ | add_executable(independent_listener independent_listener.cc) | ||
+ | target_link_libraries(independent_listener ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES} ${PROTOBUF_LIBRARIES} pthread) | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== animated_box.world ===== | ||
+ | |||
+ | |||
+ | <code xml> | ||
+ | <?xml version=" | ||
+ | <sdf version=" | ||
+ | <world name=" | ||
+ | |||
+ | <!-- Ground Plane --> | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <model name=" | ||
+ | < | ||
+ | <link name=" | ||
+ | < | ||
+ | < | ||
+ | <box> | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <visual name=" | ||
+ | < | ||
+ | <box> | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <plugin name=" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | </ |