From 2c21bc84a9251ca711507fd8095bca348cf35ec4 Mon Sep 17 00:00:00 2001 From: Matias Mattamala <mmattamala@ing.uchile.cl> Date: Sun, 30 Jul 2017 03:12:59 -0400 Subject: [PATCH] First commit, tested on kinetic --- CMakeLists.txt | 32 ++++++++ README.md | 4 +- launch/test_world.launch | 6 ++ package.xml | 30 +++++++ src/start_webots.cpp | 93 +++++++++++++++++++++ worlds/.test_world.wbproj | 11 +++ worlds/.test_world.wbt.project | 2 + worlds/test_world.wbt | 145 +++++++++++++++++++++++++++++++++ 8 files changed, 321 insertions(+), 2 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 launch/test_world.launch create mode 100644 package.xml create mode 100644 src/start_webots.cpp create mode 100644 worlds/.test_world.wbproj create mode 100644 worlds/.test_world.wbt.project create mode 100644 worlds/test_world.wbt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..181413c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 2.8.3) +project(webots_run) + +set(EXECUTABLE_NAME "start_webots") + +## Find catkin macros and libraries +## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) +## is used, also find other catkin packages +find_package(catkin REQUIRED COMPONENTS + roscpp + std_msgs +) + +## Catkin package +catkin_package( + INCLUDE_DIRS src + LIBRARIES ${PROJECT_NAME} + CATKIN_DEPENDS roscpp std_msgs +) + +include_directories(include + ${catkin_INCLUDE_DIRS} + src +) + +## Declare a C++ executable +add_executable("${EXECUTABLE_NAME}" src/start_webots.cpp) + +## Specify libraries to link a library or executable target against +target_link_libraries("${EXECUTABLE_NAME}" + ${catkin_LIBRARIES} +) diff --git a/README.md b/README.md index f6a7c54..4984b36 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# webots_ros -Isolated webots_run package from kaist_webots +# webots_run +Isolated webots_run package from kaist_webots. Also _catkinized_ :) diff --git a/launch/test_world.launch b/launch/test_world.launch new file mode 100644 index 0000000..26d76b4 --- /dev/null +++ b/launch/test_world.launch @@ -0,0 +1,6 @@ +<launch> + <!-- Run the 'start_webots' executable from the 'webots_run' package, node name 'webots' --> + <node pkg="webots_run" type="start_webots" args="$(find webots_run)/worlds/test_world.wbt" + name="webots" output="screen" required="true" /> +</launch> + diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..53bff02 --- /dev/null +++ b/package.xml @@ -0,0 +1,30 @@ +<?xml version="2.0"?> +<package> + <name>webots_run</name> + <version>0.0.0</version> + <description> + Starts the <a href="http://www.cyberbotics.com">Webots</a> Simulator using a system() call, so Webots can be run directly from a roslaunch file. + The Webots world file is specified as an argument in the launch file. + + Based on webots_run from kaist_webots package. + </description> + + <maintainer email="mmattamala@ing.uchile.cl">Matias Mattamala</maintainer> + <author>David Butterworth</author> + + <!-- License --> + <license>BSD</license> + + <!-- Dependencies --> + <buildtool_depend>catkin</buildtool_depend> + <build_depend>roscpp</build_depend> + <build_depend>std_msgs</build_depend> + <run_depend>roscpp</run_depend> + <run_depend>std_msgs</run_depend> + + <!-- The export tag contains other, unspecified, tags --> + <export> + <!-- Other tools can request additional information be placed here --> + + </export> +</package> diff --git a/src/start_webots.cpp b/src/start_webots.cpp new file mode 100644 index 0000000..f8d8451 --- /dev/null +++ b/src/start_webots.cpp @@ -0,0 +1,93 @@ +/* + * start_webots.cpp + * + * Starts the Webots Simulator using a system() call, so Webots can be + * started from a roslaunch file. + * + * Date: September 2012 + * Authors: David Butterworth + * + */ + +/* + * Copyright (c) 2012, David Butterworth, KAIST + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Willow Garage, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <ros/ros.h> +#include <iostream> // stringstream + +/* +Define Webots executable name. +The full path will come from the PATH environment variable. +Prefix with 'optirun' for Linux NVidia Bumblebee graphics driver + +Webots command line arguments: + --minimize + --mode=run + --mode=stop + (http://www.cyberbotics.com/dvd/common/doc/webots/guide/section2.2.html) +*/ + +#define WEBOTS_EXECUTABLE "webots --mode=run" +//#define WEBOTS_EXECUTABLE "optirun webots --mode=run" + +//----------------------------------------------------------------------------// + +int main(int argc, char **argv) +{ + // node name: webots + ros::init(argc, argv, "webots"); + + if ( argc != 2 ) + { + // no additional arguments, start Webots with previously opened world + ROS_INFO("Starting Webots simulator... \n"); + if (system(WEBOTS_EXECUTABLE)) {} + } + else + { + // additional arguments: + // argv[0] is full path to this ROS Node + // argv[1] is full path to world file + // argv[2] is full path to ROS log file + ROS_INFO("Starting Webots simulator... "); + ROS_INFO("Loading world: %s \n", argv[1]); + + std::stringstream ss; + ss << WEBOTS_EXECUTABLE << " " << argv[1]; + if (system( ss.str().c_str() )) {} + } + + // No need to ros::spin() + // When we quit Webots, ROS will register + // that the webots node is shutting down. + + return 0; +} + + diff --git a/worlds/.test_world.wbproj b/worlds/.test_world.wbproj new file mode 100644 index 0000000..5688e62 --- /dev/null +++ b/worlds/.test_world.wbproj @@ -0,0 +1,11 @@ +Webots Project File version 8.6 +perspectives: 000000ff00000000fd00000003000000000000000000000000fc0100000001fb0000001a0044006f00630075006d0065006e0074006100740069006f006e0000000000ffffffff0000005400ffffff00000001000001240000032cfc0200000001fb0000001400540065007800740045006400690074006f007201000000000000032c0000003c00ffffff000000030000073f000000d8fc0100000001fb0000000e0043006f006e0073006f006c006501000000000000073f0000005400ffffff000006150000032c00000001000000020000000100000008fc00000000 +simulationViewPerspectives: 000000ff000000010000000200000100000005150100000006010000000100 +sceneTreePerspectives: 000000ff0000000100000002000002590000009b0100000006010000000200 +minimizedPerspectives: +maximizedDockId: -1 +centralWidgetVisible: 1 +orthographicViewHeight: 1 +textFiles: -1 +documentationBook: +documentationPage: diff --git a/worlds/.test_world.wbt.project b/worlds/.test_world.wbt.project new file mode 100644 index 0000000..07e872a --- /dev/null +++ b/worlds/.test_world.wbt.project @@ -0,0 +1,2 @@ +Webots Project File version 6.0 +perspectives: 0 "Default" "layout2|name=3D view;caption=3D view;state=4196348;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=2.34261%;besth=4.45063%;minw=32;minh=32;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=text editor;caption=Text editor;state=6309884;dir=2;layer=0;row=0;pos=0;prop=100000;bestw=39.8975%;besth=74.8261%;minw=32;minh=32;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=console;caption=Console;state=6293500;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=100%;besth=24.8957%;minw=32;minh=32;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=scene tree;caption=Scene tree;state=6293500;dir=4;layer=1;row=0;pos=0;prop=100000;bestw=19.9854%;besth=100%;minw=32;minh=32;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=2.48902%|dock_size(4,1,0)=20.1318%|dock_size(3,0,0)=14.4949%|dock_size(2,0,0)=39.8975%|" diff --git a/worlds/test_world.wbt b/worlds/test_world.wbt new file mode 100644 index 0000000..27ead93 --- /dev/null +++ b/worlds/test_world.wbt @@ -0,0 +1,145 @@ +#VRML_SIM V6.0 utf8 +WorldInfo { + info [ + "The MyBot robot, the robot used in the tutorial of Webots" + "Author: Simon Blanchoud" + "Date: 16 AUG 2006" + ] + title "MyBot" + runRealTime TRUE +} +Viewpoint { + orientation 0.16166 0.950876 0.264008 4.13304 + position -0.911117 0.483429 -0.600393 +} +Background { + skyColor [ + 0.4 0.7 1 + ] +} +PointLight { + ambientIntensity 0.6 + attenuation 1 1 1 + color 0.991276 0.975531 1 + intensity 0.6 + location 0.75 0.5 0.5 + radius 10 +} +PointLight { + ambientIntensity 0.6 + attenuation 1 1 1 + color 0.991276 0.975531 1 + intensity 0.6 + location -0.5 0.5 0.35 + radius 10 +} +PointLight { + ambientIntensity 0.6 + attenuation 1 1 1 + color 0.991276 0.975531 1 + intensity 0.6 + location 0.45 0.5 -0.5 + radius 10 +} +PointLight { + ambientIntensity 0.6 + attenuation 1 1 1 + color 0.991276 0.975531 1 + intensity 0.6 + location -0.5 0.5 -0.35 + radius 10 +} +DEF FLOOR Transform { + translation -0.5 0 -0.5 + children [ + Shape { + geometry ElevationGrid { + color Color { + color [ + 1 1 1 + 0 0 0 + ] + } + colorPerVertex FALSE + xDimension 11 + xSpacing 0.1 + zDimension 11 + zSpacing 0.1 + } + } + ] +} +DEF WALLS Solid { + children [ + Shape { + appearance Appearance { + material Material { + diffuseColor 0.545098 0.411765 0.0784314 + specularColor 0.784314 0.588235 0.0980392 + } + } + geometry DEF WALL Extrusion { + convex FALSE + crossSection [ + 0.5 0.5 + 0.5 -0.5 + -0.5 -0.5 + -0.5 0.5 + -0.49 0.5 + -0.49 -0.49 + 0.49 -0.49 + 0.49 0.49 + -0.4899 0.49 + -0.4899 0.5 + 0.5 0.5 + ] + spine [ + 0 0 0 + 0 0.1 0 + ] + } + } + ] + name "wall" + boundingObject Group { + children [ + Transform { + translation 0.495 0.05 0 + children [ + DEF WALL_SHAPE Shape { + appearance Appearance { + material Material { + diffuseColor 1 1 1 + specularColor 1 1 1 + } + } + geometry Box { + size 0.01 0.1 1 + } + } + ] + } + Transform { + translation -0.495 0.05 0 + children [ + USE WALL_SHAPE + ] + } + Transform { + translation 0 0.05 0.495 + rotation 0 1 0 1.57 + children [ + USE WALL_SHAPE + ] + } + Transform { + translation 0 0.05 -0.495 + rotation 0 1 0 1.57 + children [ + USE WALL_SHAPE + ] + } + ] + } + locked TRUE +} -- GitLab