Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Humble hande control #28

Merged
merged 32 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
da32fbf
feat: add docker for serial lib
ChandimaFernando Mar 12, 2024
f19c704
feat: gripper control
ChandimaFernando Mar 18, 2024
2894bd0
feat: gripper control
ChandimaFernando Mar 18, 2024
243b821
fix: gripper bugs
ChandimaFernando Mar 19, 2024
4183618
fix: test path for hello moveit
ChandimaFernando Mar 19, 2024
4e69eb6
fix: cmake compile issue
ChandimaFernando Mar 20, 2024
b463812
fix: point to correct repo in docker
ChandimaFernando Mar 20, 2024
9bd76b8
refactor: add copyright
ChandimaFernando Mar 20, 2024
c3fbb99
refactor: correct settings.json
ChandimaFernando Mar 20, 2024
993ff98
fix: move serial to ra separate repo
ChandimaFernando Mar 21, 2024
3d1d982
fix: remove submodule
ChandimaFernando Mar 21, 2024
c8859ba
fix: simplify gripper service
ChandimaFernando Mar 21, 2024
6af1fee
fix: add missing links to yml
ChandimaFernando Mar 21, 2024
3156f6e
FIX: PATH CORRECTION
ChandimaFernando Mar 21, 2024
6f45c91
fix: correct runtime cmd for dockerfile
ChandimaFernando Mar 21, 2024
6ecc3a7
refactor: remove extra files
ChandimaFernando Mar 21, 2024
d0d86d5
fix: change node structure
ChandimaFernando Mar 25, 2024
1acebbc
feat: build one docker img for all containers
ChandimaFernando Mar 25, 2024
9231df0
fix: gripper scope error
ChandimaFernando Mar 25, 2024
adb286b
fix: add ignore paths for lint
ChandimaFernando Mar 26, 2024
f97c3a3
fix: remove setup.sh
ChandimaFernando Mar 26, 2024
efc9bf6
fix: lint errors
ChandimaFernando Mar 26, 2024
a79af47
fix: point to build.sh
ChandimaFernando Mar 28, 2024
295887a
fix: cmake args temp fix
ChandimaFernando Mar 28, 2024
e4c7420
fix: cleaned up Dockerfile
ChandimaFernando Mar 28, 2024
914fcc1
fix: correct build location
ChandimaFernando Mar 28, 2024
5317759
fix: more path corrections
ChandimaFernando Mar 28, 2024
e50afb1
fix: correct and clean dockerfile
ChandimaFernando Mar 28, 2024
be77ef5
fix: correct tests
ChandimaFernando Mar 28, 2024
87deab4
refactor: remove unnecessary images
ChandimaFernando Mar 28, 2024
944c003
refactor: remove ros examples
ChandimaFernando Mar 28, 2024
e786a51
Apply suggestions from code review
maffettone Mar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/lint/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e

./setup.sh
# ./setup.sh
ament_${LINTER} src/
10 changes: 9 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ set -e

# Set the default build type
BUILD_TYPE=RelWithDebInfo

source /opt/ros/${ROS_DISTRO}/setup.bash && colcon build \
--merge-install \
--symlink-install \
--packages-select ur3e_hande_robot_description serial robotiq_driver pdf_beamtime_interfaces \
--cmake-args "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DCMAKE_EXPORT_COMPILE_COMMANDS=On" \
--cmake-args "-DCMAKE_CXX_FLAGS=-Wall -Wextra -Wpedantic"

colcon build \
--merge-install \
--symlink-install \
--cmake-args "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DCMAKE_EXPORT_COMPILE_COMMANDS=On" \
-Wall -Wextra -Wpedantic
-Wall -Wextra -Wpedantic
44 changes: 44 additions & 0 deletions docker/erobs-common-img/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM osrf/ros:humble-desktop-full

# Set display
ENV DISPLAY :1

RUN apt-get update \
&& apt-get -y install \
python3-pip \
ros-${ROS_DISTRO}-rclpy \
ros-${ROS_DISTRO}-ur \
build-essential \
python3-colcon-common-extensions
RUN apt-get install -y x11vnc xvfb
# Clean up
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install rosdep && \
rosdep update

RUN mkdir /root/ws -p

WORKDIR /root/ws

# TODO @ChandimaFernando. Revert back after tests. RUN git clone https://github.com/maffettone/erobs.git -b humble
RUN git clone https://github.com/ChandimaFernando/erobs.git -b humble_hande_control

WORKDIR /root/ws/erobs/
RUN /bin/bash -c ". ./setup.sh"

WORKDIR /root/ws/
RUN /bin/bash -c ". ./erobs/build.sh"

ENV ROBOT_IP=192.168.56.101
ENV REVERSE_IP=192.168.56.102
ENV UR_TYPE="ur3e"
ENV LAUNCH_RVIZ="false"
ENV DESCRIPTION_PKG="ur3e_hande_robot_description"
ENV DESCRIPTION_FILE="ur_with_hande.xacro"
ENV CONFIG_PKG="ur3e_hande_moveit_config"
ENV CONFIG_FILE="ur.srdf"

# VNC viewer
EXPOSE 5901
37 changes: 37 additions & 0 deletions docker/erobs-common-img/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file contains commands to launch multiple containers of the same docker image.
(TODO ChandimaFernando : Change the repo link to nsls-II repo.)

export ROBOT_IP=10.67.218.141
export UR_TYPE="ur3e"
export LAUNCH_RVIZ="false"
export DESCRIPTION_PKG="ur3e_hande_robot_description"
export DESCRIPTION_FILE="ur_with_hande.xacro"
export CONFIG_PKG="ur3e_hande_moveit_config"
export CONFIG_FILE="ur.srdf"
export ROS_DISTRO=humble

# Enable the connection between the UR robot and the VM
podman run -it --network host --ipc=host --pid=host \
--env ROBOT_IP=$ROBOT_IP \
--env UR_TYPE=$UR_TYPE \
--env ROS_DISTRO=$ROS_DISTRO \
ghcr.io/chandimafernando/erobs-common-img:latest \
/bin/sh -c "printenv && . /opt/ros/${ROS_DISTRO}/setup.sh && . /root/ws/install/setup.sh && ros2 launch ur_robot_driver ur_control.launch.py ur_type:=${UR_TYPE} robot_ip:=${ROBOT_IP} launch_rviz:=false tool_voltage:=24"

# Run gripper service to enable the gripper
podman run -it --network host --ipc=host --pid=host \
ghcr.io/chandimafernando/erobs-common-img:latest \
/bin/bash -c ". /root/ws/install/setup.sh && \
ros2 run gripper_service gripper_service"

# Launch move_group
podman run -it --network host --ipc=host --pid=host \
--env ROBOT_IP=$ROBOT_IP \
--env UR_TYPE=$UR_TYPE \
--env ROS_DISTRO=$ROS_DISTRO \
--env DESCRIPTION_PKG=$DESCRIPTION_PKG \
--env DESCRIPTION_FILE=$DESCRIPTION_FILE \
--env CONFIG_PKG=$CONFIG_PKG \
--env CONFIG_FILE=$CONFIG_FILE \
ghcr.io/chandimafernando/erobs-common-img:latest \
/bin/sh -c "printenv && . /opt/ros/${ROS_DISTRO}/setup.sh && . /root/ws/install/setup.sh && ros2 launch ur_moveit_config ur_moveit.launch.py ur_type:=${UR_TYPE} launch_rviz:=${LAUNCH_RVIZ} description_package:=${DESCRIPTION_PKG} launch_servo:=false description_file:=${DESCRIPTION_FILE} moveit_config_package:=${CONFIG_PKG} moveit_config_file:=${CONFIG_FILE}"
56 changes: 56 additions & 0 deletions src/gripper_service/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.8)
project(gripper_service)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(pdf_beamtime_interfaces REQUIRED)
find_package(robotiq_driver REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

set(dependencies
rclcpp
rclcpp_components
pdf_beamtime_interfaces
robotiq_driver
)

include_directories(include) # This makes sure the libraries are visible

add_executable(gripper_service src/gripper_service.cpp)
ament_target_dependencies(gripper_service ${dependencies})

install(TARGETS
gripper_service
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY DESTINATION share/${PROJECT_NAME})

install(
DIRECTORY include/
DESTINATION include
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
45 changes: 45 additions & 0 deletions src/gripper_service/include/gripper_service/gripper_service.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*Copyright 2023 Brookhaven National Laboratory
BSD 3 Clause License. See LICENSE.txt for details.*/
#pragma once

#include <iostream>
#include <thread>
#include <memory>
#include <string>
#include <map>

#include <rclcpp/rclcpp.hpp>

#include "pdf_beamtime_interfaces/srv/gripper_control_msg.hpp"

#include <robotiq_driver/robotiq_gripper_interface.hpp>

class GripperService : public rclcpp::Node
{
private:
/// @brief your serial port goes here
const char * kComPort = "/tmp/ttyUR";
const int kSlaveID = 0x09;

// rclcpp::Node::SharedPtr node_;
RobotiqGripperInterface gripper_;

/// @brief Gripper commands as enums for ease of use
enum class Gripper_Command {OPEN, CLOSE, PARTIAL, ACTIVE, DEACTIVE};

std::map<std::string, Gripper_Command> gripper_command_map_ = {
{"ACTIVE", Gripper_Command::ACTIVE},
{"DEACTIVE", Gripper_Command::DEACTIVE},
{"OPEN", Gripper_Command::OPEN},
{"CLOSE", Gripper_Command::CLOSE},
{"PARTIAL", Gripper_Command::PARTIAL}
};

/// @brief callback function for the gripper service
void gripper_controller(
const std::shared_ptr<pdf_beamtime_interfaces::srv::GripperControlMsg::Request> request,
std::shared_ptr<pdf_beamtime_interfaces::srv::GripperControlMsg::Response> response);

public:
GripperService();
};
22 changes: 22 additions & 0 deletions src/gripper_service/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>gripper_service</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="wfernando1@bnl.gov">wfernando1</maintainer>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<buildtool_depend>pdf_beamtime_interfaces</buildtool_depend>
<buildtool_depend>robotiq_driver</buildtool_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
98 changes: 98 additions & 0 deletions src/gripper_service/src/gripper_service.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*Copyright 2023 Brookhaven National Laboratory
BSD 3 Clause License. See LICENSE.txt for details.*/
#include <gripper_service/gripper_service.hpp>

using namespace std::placeholders;

GripperService::GripperService()
: Node("gripper_server_node"),
gripper_(kComPort, kSlaveID)
{
RCLCPP_INFO(this->get_logger(), "Activate the gripper ...");
// Clear the registers
gripper_.deactivateGripper();

// Activate the gripper
gripper_.activateGripper();
gripper_.setSpeed(0x0F);

RCLCPP_INFO(this->get_logger(), "Activation is successful");

rclcpp::Service<pdf_beamtime_interfaces::srv::GripperControlMsg>::SharedPtr service =
this->create_service<pdf_beamtime_interfaces::srv::GripperControlMsg>(
"gripper_service",
std::bind(
&GripperService::gripper_controller, this, _1, _2));
RCLCPP_INFO(this->get_logger(), "Ready to receive gripper commands.");
}

void GripperService::gripper_controller(
const std::shared_ptr<pdf_beamtime_interfaces::srv::GripperControlMsg::Request> request,
std::shared_ptr<pdf_beamtime_interfaces::srv::GripperControlMsg::Response> response)
{
int status = 0;
try {
// conver the request command string to the mapping enum
Gripper_Command gripper_command_enum = gripper_command_map_[request->command];

switch (gripper_command_enum) {
case Gripper_Command::ACTIVE:
// Activate the gripper
gripper_.deactivateGripper();
gripper_.activateGripper();
RCLCPP_INFO(this->get_logger(), "Activation is successful");

break;

case Gripper_Command::DEACTIVE:
// Deactivate the gripper
gripper_.deactivateGripper();
RCLCPP_INFO(this->get_logger(), "Gripper is Deactivated");

break;

case Gripper_Command::PARTIAL:
{
// Closes the gripper to the percentage set by request->grip
uint8_t val = request->grip * 2.55; // convert the scales from 01-100 to 0-255
gripper_.setGripperPosition(val);
RCLCPP_INFO(this->get_logger(), "Gripper is Open");
}
break;

case Gripper_Command::OPEN:
// Open the gripper fully
gripper_.setGripperPosition(0x00);
RCLCPP_INFO(this->get_logger(), "Gripper is Open");
break;

case Gripper_Command::CLOSE:
// Close the gripper fully
gripper_.setGripperPosition(0xFF);
RCLCPP_INFO(this->get_logger(), "Gripper is Close");
break;

default:
break;
}
status = 1;
} catch (const std::exception & e) {
RCLCPP_ERROR(this->get_logger(), e.what());
status = 0;
}

// Send the response back
response->results = status;
}

int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);

auto gripper_server_node = std::make_shared<GripperService>();

rclcpp::spin(gripper_server_node);
rclcpp::shutdown();

return 0;
}
2 changes: 1 addition & 1 deletion src/hello_moveit/src/hello_moveit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char * argv[])
// Create the MoveIt MoveGroup Interface
RCLCPP_INFO(logger, "assembling move_group_interface");
using moveit::planning_interface::MoveGroupInterface;
auto move_group_interface = MoveGroupInterface(node, "ur_manipulator");
auto move_group_interface = MoveGroupInterface(node, "ur_arm");

// Set a target Pose
auto const target_pose = [] {
Expand Down
1 change: 1 addition & 0 deletions src/pdf_beamtime_interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rosidl_generate_interfaces(${PROJECT_NAME}
"srv/BoxObstacleMsg.srv"
"srv/CylinderObstacleMsg.srv"
"srv/BlueskyInterruptMsg.srv"
"srv/GripperControlMsg.srv"
)


Expand Down
4 changes: 4 additions & 0 deletions src/pdf_beamtime_interfaces/srv/GripperControlMsg.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
string command
int32 grip # 0-100, percentage of open/close of the gripper
---
int32 results
8 changes: 8 additions & 0 deletions src/ros2.repos
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ repositories:
type: git
url: https://github.com/ros2/examples.git
version: humble
gripper:
type: git
url: https://github.com/PickNikRobotics/ros2_robotiq_gripper.git
version: cmake-external-project-serial
serial:
type: git
url: https://github.com/PickNikRobotics/serial-release.git
version: release/humble/serial
Loading