diff --git a/00_GettingStarted/docker/i2r/Dockerfile b/00_GettingStarted/docker/i2r/Dockerfile index 78e359bc4f80514ea74e4d34c337fa7507a53888..dab1ce7a137f8b336fc176b925986dfe9d4b2296 100644 --- a/00_GettingStarted/docker/i2r/Dockerfile +++ b/00_GettingStarted/docker/i2r/Dockerfile @@ -19,5 +19,22 @@ RUN apt-get update && apt-get dist-upgrade -y \ RUN cd ~/catkin_ws/src RUN cd ~/catkin_ws \ -&& catkin config --extend /opt/ros/${ROS_DISTRO} --cmake-args -DCMAKE_BUILD_TYPE=Release \ +&& catkin config --extend /opt/ros/${ROS_DISTRO} --cmake-args -DCMAKE_BUILD_TYPE=Release +RUN apt-get update && apt-get install -y ros-melodic-joy ros-melodic-teleop-twist-joy \ + ros-melodic-teleop-twist-keyboard ros-melodic-laser-proc \ + ros-melodic-rgbd-launch ros-melodic-depthimage-to-laserscan \ + ros-melodic-rosserial-arduino ros-melodic-rosserial-python \ + ros-melodic-rosserial-server ros-melodic-rosserial-client \ + ros-melodic-rosserial-msgs ros-melodic-amcl ros-melodic-map-server \ + ros-melodic-move-base ros-melodic-urdf ros-melodic-xacro \ + ros-melodic-compressed-image-transport ros-melodic-rqt* \ + ros-melodic-gmapping ros-melodic-navigation ros-melodic-interactive-markers + + RUN apt-get update && apt-get install -y ros-melodic-dynamixel-sdk \ + ros-melodic-turtlebot3-msgs ros-melodic-turtlebot3 + + RUN echo "export TURTLEBOT3_MODEL=burger" >> ~/.bashrc && source ~/.bashrc + + RUN cd ~/catkin_ws/src + RUN git clone -b melodic-devel https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git diff --git a/00_GettingStarted/docker/i2r/catkin_ws/src/task_3/CMakeLists.txt b/00_GettingStarted/docker/i2r/catkin_ws/src/task_3/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7b5f53a9e4b9dae030ea9af199c45944dd273958 --- /dev/null +++ b/00_GettingStarted/docker/i2r/catkin_ws/src/task_3/CMakeLists.txt @@ -0,0 +1,206 @@ +cmake_minimum_required(VERSION 3.0.2) +project(task_3) + +## Compile as C++11, supported in ROS Kinetic and newer +# add_compile_options(-std=c++11) + +## 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 + geometry_msgs + rospy + sensor_msgs +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + + +## Uncomment this if the package has a setup.py. This macro ensures +## modules and global scripts declared therein get installed +## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html +# catkin_python_setup() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a exec_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder +# add_message_files( +# FILES +# Message1.msg +# Message2.msg +# ) + +## Generate services in the 'srv' folder +# add_service_files( +# FILES +# Service1.srv +# Service2.srv +# ) + +## Generate actions in the 'action' folder +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here +# generate_messages( +# DEPENDENCIES +# geometry_msgs# sensor_msgs +# ) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a exec_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if your package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( +# INCLUDE_DIRS include + LIBRARIES task_3 + CATKIN_DEPENDS geometry_msgs rospy sensor_msgs +# DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +include_directories( +# include + ${catkin_INCLUDE_DIRS} +) + +## Declare a C++ library +# add_library(${PROJECT_NAME} +# src/${PROJECT_NAME}/task_3.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +## With catkin_make all packages are built within a single CMake context +## The recommended prefix ensures that target names across packages don't collide +# add_executable(${PROJECT_NAME}_node src/task_3_node.cpp) + +## Rename C++ executable without prefix +## The above recommended prefix causes long target names, the following renames the +## target back to the shorter version for ease of user use +## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" +# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(${PROJECT_NAME}_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +# Mark executable scripts (Python etc.) for installation +# in contrast to setup.py, you can choose the destination +catkin_install_python(PROGRAMS + scripts/simple_auto_drive.py + DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +) + +## Mark executables for installation +## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html +# install(TARGETS ${PROJECT_NAME}_node +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark libraries for installation +## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html +# install(TARGETS ${PROJECT_NAME} +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_task_3.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) diff --git a/00_GettingStarted/docker/i2r/catkin_ws/src/task_3/package.xml b/00_GettingStarted/docker/i2r/catkin_ws/src/task_3/package.xml new file mode 100644 index 0000000000000000000000000000000000000000..5ea3db59cd156afce08cc43526bce04275f52d3c --- /dev/null +++ b/00_GettingStarted/docker/i2r/catkin_ws/src/task_3/package.xml @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<package format="2"> + <name>task_3</name> + <version>0.0.0</version> + <description>The task_3 package</description> + + <!-- One maintainer tag required, multiple allowed, one person per tag --> + <!-- Example: --> + <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> --> + <maintainer email="robotics@todo.todo">robotics</maintainer> + + + <!-- One license tag required, multiple allowed, one license per tag --> + <!-- Commonly used license strings: --> + <!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --> + <license>TODO</license> + + + <!-- Url tags are optional, but multiple are allowed, one per tag --> + <!-- Optional attribute type can be: website, bugtracker, or repository --> + <!-- Example: --> + <!-- <url type="website">http://wiki.ros.org/task_3</url> --> + + + <!-- Author tags are optional, multiple are allowed, one per tag --> + <!-- Authors do not have to be maintainers, but could be --> + <!-- Example: --> + <!-- <author email="jane.doe@example.com">Jane Doe</author> --> + + + <!-- The *depend tags are used to specify dependencies --> + <!-- Dependencies can be catkin packages or system dependencies --> + <!-- Examples: --> + <!-- Use depend as a shortcut for packages that are both build and exec dependencies --> + <!-- <depend>roscpp</depend> --> + <!-- Note that this is equivalent to the following: --> + <!-- <build_depend>roscpp</build_depend> --> + <!-- <exec_depend>roscpp</exec_depend> --> + <!-- Use build_depend for packages you need at compile time: --> + <!-- <build_depend>message_generation</build_depend> --> + <!-- Use build_export_depend for packages you need in order to build against this package: --> + <!-- <build_export_depend>message_generation</build_export_depend> --> + <!-- Use buildtool_depend for build tool packages: --> + <!-- <buildtool_depend>catkin</buildtool_depend> --> + <!-- Use exec_depend for packages you need at runtime: --> + <!-- <exec_depend>message_runtime</exec_depend> --> + <!-- Use test_depend for packages you need only for testing: --> + <!-- <test_depend>gtest</test_depend> --> + <!-- Use doc_depend for packages you need only for building documentation: --> + <!-- <doc_depend>doxygen</doc_depend> --> + <buildtool_depend>catkin</buildtool_depend> + <build_depend>geometry_msgs</build_depend> + <build_depend>rospy</build_depend> + <build_depend>sensor_msgs</build_depend> + <build_export_depend>geometry_msgs</build_export_depend> + <build_export_depend>rospy</build_export_depend> + <build_export_depend>sensor_msgs</build_export_depend> + <exec_depend>geometry_msgs</exec_depend> + <exec_depend>rospy</exec_depend> + <exec_depend>sensor_msgs</exec_depend> + + + <!-- The export tag contains other, unspecified, tags --> + <export> + <!-- Other tools can request additional information be placed here --> + + </export> +</package> diff --git a/00_GettingStarted/docker/i2r/catkin_ws/src/task_3/scripts/simple_auto_drive.py b/00_GettingStarted/docker/i2r/catkin_ws/src/task_3/scripts/simple_auto_drive.py new file mode 100644 index 0000000000000000000000000000000000000000..e08c2e77357a0dfac351e0d51ed06cffc5ff55b9 --- /dev/null +++ b/00_GettingStarted/docker/i2r/catkin_ws/src/task_3/scripts/simple_auto_drive.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +# Task 3 + + +import rospy +from sensor_msgs.msg import LaserScan +from geometry_msgs.msg import Twist + +def callback(dt): + print '-------------------------------------------' + print 'Range data at 0 deg: {}'.format(dt.ranges[0]) + print 'Range data at 15 deg: {}'.format(dt.ranges[15]) + print 'Range data at 345 deg: {}'.format(dt.ranges[345]) + print '-------------------------------------------' + thr1 = 0.8 # Laser scan range threshold + thr2 = 0.8 + if dt.ranges[0]>thr1 and dt.ranges[15]>thr2 and dt.ranges[345]>thr2: # Checks if there are obstacles in front and + # 15 degrees left and right (Try changing the + # the angle values as well as the thresholds) + move.linear.x = 0.5 # go forward (linear velocity) + move.angular.z = 0.0 # do not rotate (angular velocity) + else: + move.linear.x = 0.0 # stop + move.angular.z = 0.5 # rotate counter-clockwise + if dt.ranges[0]>thr1 and dt.ranges[15]>thr2 and dt.ranges[345]>thr2: + move.linear.x = 0.5 + move.angular.z = 0.0 + pub.publish(move) # publish the move object + + +move = Twist() # Creates a Twist message type object +rospy.init_node('obstacle_avoidance_node') # Initializes a node +pub = rospy.Publisher("/cmd_vel", Twist, queue_size=10) # Publisher object which will publish "Twist" type messages + # on the "/cmd_vel" Topic, "queue_size" is the size of the + # outgoing message queue used for asynchronous publishing + +sub = rospy.Subscriber("/scan", LaserScan, callback) # Subscriber object which will listen "LaserScan" type messages + # from the "/scan" Topic and call the "callback" function + # each time it reads something from the Topic + +rospy.spin() # Loops infinitely until someone stops the program execution \ No newline at end of file diff --git a/00_GettingStarted/docker/i2r/catkin_ws/src/testing_moveit/scripts/testing_moveit.py b/00_GettingStarted/docker/i2r/catkin_ws/src/testing_moveit/scripts/testing_moveit.py index e7f4a7f4d0fbad5b6534a352812b78db2d04f605..8f067186b6efe26b967e203ec5b70eb55317198d 100644 --- a/00_GettingStarted/docker/i2r/catkin_ws/src/testing_moveit/scripts/testing_moveit.py +++ b/00_GettingStarted/docker/i2r/catkin_ws/src/testing_moveit/scripts/testing_moveit.py @@ -9,6 +9,7 @@ import geometry_msgs.msg import moveit_msgs.msg from trajectory_msgs.msg import JointTrajectoryPoint import tf +from math import pi print("--- Imports done! ---") @@ -66,9 +67,10 @@ display_trajectories_publisher = rospy.Publisher("/move_group/display_planned_pa print("Executed: display_trajectories_publisher = rospy.Publisher(\"/move_group/display_planned_path\", moveit_msgs.msg.DisplayTrajectory, queue_size=20)") rospy.sleep(5) print('Planning scene objects:', scene.get_objects()) -scene.remove_world_object("table1") +scene.remove_world_object("table") scene.remove_world_object("table2") scene.remove_world_object("object1") +scene.remove_world_object("box1") rospy.sleep(5) #### Defining Objects @@ -79,19 +81,164 @@ box1_id = 'box1' target_id = 'target' tool_id = 'tool' -table_ground = 0.65 +table_ground = 0.3 table_size = [0.2, 0.7, 0.01] box_1_size = [0.1, 0.05, 0.05] target_size = [0.02, 0.01, 0.12] ##### Placing objects +# Table table_pose = geometry_msgs.msg.PoseStamped() table_pose.header.frame_id = planning_frame -table_pose.pose.position.x = 0 +table_pose.pose.position.x = 0.5 table_pose.pose.position.y = 0 table_pose.pose.position.z = (table_ground + table_size[2]/2) table_pose.pose.orientation.w = 1.0 scene.add_box(table_id, table_pose, table_size) +print("Added " + table_id + " to the scene!") -rospy.sleep(5) \ No newline at end of file +# Box +box_pose = geometry_msgs.msg.PoseStamped() +box_pose.header.frame_id = planning_frame +box_pose.pose.position.x = 0.5 +box_pose.pose.position.y = 0 +box_pose.pose.position.z = (table_ground + table_size[2] + box_1_size[2]/2) +box_pose.pose.orientation.w = 1.0 +scene.add_box(box1_id, box_pose, box_1_size) +print("Added " + box1_id + " to the scene!") + +rospy.sleep(5) + +#### Grasp + +# Documentation of message definition: https://docs.ros.org/en/melodic/api/moveit_msgs/html/msg/Grasp.html + +g = moveit_msgs.msg.Grasp() + +g.id = "grasp_box1" + +# defining the grasp pose +grasp_pose = geometry_msgs.msg.PoseStamped() +grasp_pose.header.frame_id = planning_frame +grasp_pose.pose.position.x = -0.5 +grasp_pose.pose.position.y = 0 +grasp_pose.pose.position.z = 0.55 +quaternion = tf.transformations.quaternion_from_euler(math.radians(180), 0, math.radians(135)) +print("-----------------------------------------------") +print("Quaternion: ",quaternion) +print("-----------------------------------------------") +grasp_pose.pose.orientation.x = quaternion[0] +grasp_pose.pose.orientation.y = quaternion[1] +grasp_pose.pose.orientation.z = quaternion[2] +grasp_pose.pose.orientation.w = quaternion[3] +#grasp_pose.pose.orientation.x = 0.924 +#grasp_pose.pose.orientation.y = -0.383 +#grasp_pose.pose.orientation.z = 0 +#grasp_pose.pose.orientation.w = 0 + + + +print("Grasp pose z-position = "+str((table_ground + table_size[2] + box_1_size[2]/2))) + + +move_group.set_planning_time(15) + +joint_goal = move_group.get_current_joint_values() +joint_goal[0] = 0 +joint_goal[1] = -pi/4 +joint_goal[2] = 0 +joint_goal[3] = -pi/2 +joint_goal[4] = 0 +joint_goal[5] = pi/3 +joint_goal[6] = 0 + +# The go command can be called with joint values, poses, or without any +# parameters if you have already set the pose or joint target for the group +move_group.go(joint_goal, wait=True) + +# Calling ``stop()`` ensures that there is no residual movement +move_group.stop() + +#move_group.set_goal_tolerance(0.2) +move_group.set_goal_position_tolerance(1E-2) +move_group.set_goal_orientation_tolerance(1E-3) +move_group.set_num_planning_attempts(5) +move_group.set_planning_time(10) +move_group.set_planner_id("RRTstar") + +print("-----------------------------------------------") +print("Known constraints: ",move_group.get_known_constraints()) +print("-----------------------------------------------") +print("Path constraints: ",move_group.get_path_constraints()) +print("-----------------------------------------------") +print("Plan: ",move_group.plan()) +print("-----------------------------------------------") + +move_group.set_pose_target(grasp_pose) +plan = move_group.go(wait=True) +move_group.stop() +move_group.clear_pose_targets() + +print("-----------------------------------------------") +print("Current Pose: ",move_group.get_current_pose().pose) +print("-----------------------------------------------") +print("Desired Pose: ", grasp_pose) +print("-----------------------------------------------") + +print("Defining Grasp") +grasps = [] + +g = moveit_msgs.msg.Grasp() +g.allowed_touch_objects.append("box1") +g.allowed_touch_objects.append("table") + + +# Setting grasp pose +#grasp_pose = geometry_msgs.msg.PoseStamped() +g.grasp_pose.header.frame_id = planning_frame +g.grasp_pose.pose.position.x = 0.5 +g.grasp_pose.pose.position.y = 0 +g.grasp_pose.pose.position.z = (table_ground + table_size[2] + box_1_size[2] + 0.058 + 0.1) +quaternion = tf.transformations.quaternion_from_euler(math.radians(180), 0, math.radians(135)) +g.grasp_pose.pose.orientation.x = quaternion[0] +g.grasp_pose.pose.orientation.y = quaternion[1] +g.grasp_pose.pose.orientation.z = quaternion[2] +g.grasp_pose.pose.orientation.w = quaternion[3] + + +# Setting pre-grasp approach +g.pre_grasp_approach.direction.header.frame_id = planning_frame +g.pre_grasp_approach.direction.vector.z = -1.0 +g.pre_grasp_approach.min_distance = 0.01 +g.pre_grasp_approach.desired_distance = 0.1 + +# Setting post-grasp retreat +g.post_grasp_retreat.direction.header.frame_id = planning_frame +g.post_grasp_retreat.direction.vector.x = 1.0 +g.post_grasp_retreat.min_distance = 0.15 +g.post_grasp_retreat.desired_distance = 0.25 + +# Setting posture of eef before grasp +g.pre_grasp_posture.header.frame_id = planning_frame +g.pre_grasp_posture.joint_names = ["panda_finger_joint1","panda_finger_joint2"] +pos_open = JointTrajectoryPoint() +pos_open.positions.append(float(0.06)) +g.pre_grasp_posture.points.append(pos_open) + + +#### set the grasp posture +g.grasp_posture.header.frame_id = planning_frame +g.grasp_posture.joint_names = ["panda_finger_joint1","panda_finger_joint2"] +pos_close = JointTrajectoryPoint() +pos_close.positions.append(float(0.00)) +g.grasp_posture.points.append(pos_close) + +print("g: ",g) + +#### Grasping +grasps.append(g) + +print("-----------------------------------------------") +print("Executing Pick task") +move_group.pick("box1", grasps) \ No newline at end of file diff --git a/00_GettingStarted/docker/i2r/catkin_ws/src/turtlebot3_simulations b/00_GettingStarted/docker/i2r/catkin_ws/src/turtlebot3_simulations new file mode 160000 index 0000000000000000000000000000000000000000..5172a8ed535173226cad39f4583ce6b15e0a30c1 --- /dev/null +++ b/00_GettingStarted/docker/i2r/catkin_ws/src/turtlebot3_simulations @@ -0,0 +1 @@ +Subproject commit 5172a8ed535173226cad39f4583ce6b15e0a30c1 diff --git a/00_GettingStarted/docker/i2r/catkin_ws/src/universal_robot b/00_GettingStarted/docker/i2r/catkin_ws/src/universal_robot deleted file mode 160000 index 6507bb6756d0065d49b76230ff55f875f099a827..0000000000000000000000000000000000000000 --- a/00_GettingStarted/docker/i2r/catkin_ws/src/universal_robot +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6507bb6756d0065d49b76230ff55f875f099a827