Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions autonomy/teleop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Teleop
## Samples
To run rosbridge listener:
```
ros2 run rosbridge_listener rosbridge_listener_node
```

To run rosbridge publisher:

```
ros2 run rosbridge_publisher rosbridge_publisher_node
```

## Running Rosbridge Server
Rosbridge server will relay ros topics to humanoid-server. To run, use:
```
ros2 launch rosbridge_server rosbridge_websocket_launch.xml
```

## Full Setup for Testing VR -> ROS
These commands were run with the autonomy/samples folder deleted, since some packages may overlap

```bash

# In humanoid repo:
cd autonomy
colcon build
source install/setup.bash
ros2 run rosbridge_listener rosbridge_listener_node

# Then, in another terminal:
cd autonomy
source install/setup.bash
ros2 launch rosbridge_server rosbridge_websocket_launch.xml

# In humanoid-server repo:
npm run dev
```

Then, connect to ws://localhost:3000 (default websocket url) and send an example hand pose message:
```
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
```
The message should appear in the terminal where you ran the rosbridge listener node

45 changes: 45 additions & 0 deletions autonomy/teleop/rosbridge_listener/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.8)
project(rosbridge_listener)

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(sample_msgs REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

add_library(rosbridge_listener_lib
src/rosbridge_listener_core.cpp)

target_include_directories(rosbridge_listener_lib
PUBLIC include)

add_executable(rosbridge_listener_node src/rosbridge_listener_node.cpp)

ament_target_dependencies(rosbridge_listener_node rclcpp std_msgs sample_msgs)
target_include_directories(rosbridge_listener_node PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(rosbridge_listener_node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17

install(TARGETS rosbridge_listener_node
DESTINATION lib/${PROJECT_NAME})

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()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef ROSBRIDGE_LISTENER_NODE_HPP_
#define ROSBRIDGE_LISTENER_NODE_HPP_

#include "rclcpp/rclcpp.hpp"

#include "sample_msgs/msg/hand_pose.hpp"

#include "rosbridge_listener_core.hpp"

/**
* Implementation of a ROS2 node that listens to the "unfiltered" and "filtered"
* topics and echoes the operating frequency of the topic to the console.
*/
class ROSbridgeListenerNode : public rclcpp::Node {
public:
ROSbridgeListenerNode();

private:
std::string
hand_pose_to_string(const sample_msgs::msg::HandPose::SharedPtr pose);

void hand_pose_callback(const sample_msgs::msg::HandPose::SharedPtr msg);

rclcpp::Subscription<sample_msgs::msg::HandPose>::SharedPtr hand_pose_sub_;
};

#endif
21 changes: 21 additions & 0 deletions autonomy/teleop/rosbridge_listener/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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>rosbridge_listener</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">yichen</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>rclcpp</depend>
<depend>sample_msgs</depend>

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

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Empty file.
38 changes: 38 additions & 0 deletions autonomy/teleop/rosbridge_listener/src/rosbridge_listener_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "rosbridge_listener_node.hpp"

#include <algorithm>
#include <string>

ROSbridgeListenerNode::ROSbridgeListenerNode() : Node("rosbridge_listener") {

hand_pose_sub_ = this->create_subscription<sample_msgs::msg::HandPose>(
"teleop", 10,
std::bind(&ROSbridgeListenerNode::hand_pose_callback, this,
std::placeholders::_1));
}

std::string ROSbridgeListenerNode::hand_pose_to_string(
const sample_msgs::msg::HandPose::SharedPtr pose) {
std::string s;
std::vector<float> hand_pose = pose->data;
s += "[";
for (int i = 0; i < hand_pose.size(); i++) {
s += std::to_string(hand_pose[i]);
s += ",";
}
s += "]";
return s;
}

void ROSbridgeListenerNode::hand_pose_callback(
const sample_msgs::msg::HandPose::SharedPtr msg) {
RCLCPP_INFO(this->get_logger(), "Received Hand Data: %s",
hand_pose_to_string(msg).c_str());
}

int main(int argc, char **argv) {
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<ROSbridgeListenerNode>());
rclcpp::shutdown();
return 0;
}
44 changes: 44 additions & 0 deletions autonomy/teleop/rosbridge_publisher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.8)
project(rosbridge_publisher)

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(std_msgs REQUIRED)
find_package(sample_msgs REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

add_library(rosbridge_publisher_lib src/rosbridge_publisher_core.cpp)

target_include_directories(rosbridge_publisher_lib PUBLIC include)

add_executable(rosbridge_publisher_node src/rosbridge_publisher_node.cpp)
ament_target_dependencies(rosbridge_publisher_lib rclcpp std_msgs sample_msgs)
target_link_libraries(rosbridge_publisher_node rosbridge_publisher_lib)
target_include_directories(rosbridge_publisher_node PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(rosbridge_publisher_node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17

install(TARGETS rosbridge_publisher_node
DESTINATION lib/${PROJECT_NAME})

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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef ROSBRIDGE_PUBLISHER_CORE_HPP_
#define ROSBRIDGE_PUBLISHER_CORE_HPP_

#include "rclcpp/rclcpp.hpp"

#include "sample_msgs/msg/hand_pose.hpp"

class ROSbridgePublisherCore {
public:
explicit ROSbridgePublisherCore();

std::string hand_pose_to_string(const sample_msgs::msg::HandPose pose);

private:
};

#endif // AGGREGATOR_CORE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef ROSBRIDGE_PUBLISHER_NODE_HPP_
#define ROSBRIDGE_PUBLISHER_NODE_HPP_

#include "rclcpp/rclcpp.hpp"

#include "sample_msgs/msg/hand_pose.hpp"

#include "rosbridge_publisher_core.hpp"

/**
* Implementation of a ROS2 node that listens to the "unfiltered" and "filtered"
* topics and echoes the operating frequency of the topic to the console.
*/
class ROSbridgePublisherNode : public rclcpp::Node {
public:
ROSbridgePublisherNode();

private:
void timer_callback();

rclcpp::TimerBase::SharedPtr timer_;

rclcpp::Publisher<sample_msgs::msg::HandPose>::SharedPtr hand_pose_pub_;

ROSbridgePublisherCore rosbridge_publisher_;
};

#endif
22 changes: 22 additions & 0 deletions autonomy/teleop/rosbridge_publisher/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>rosbridge_publisher</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">yichen</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>rclcpp</depend>
<depend>sample_msgs</depend>
<depend>std_msgs</depend>

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

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <chrono>
#include <cmath>

#include "rosbridge_publisher_core.hpp"

ROSbridgePublisherCore::ROSbridgePublisherCore() {}

std::string ROSbridgePublisherCore::hand_pose_to_string(
const sample_msgs::msg::HandPose pose) {
std::string s;
std::vector<float> hand_pose = pose.data;
s += "[";
for (int i = 0; i < hand_pose.size(); i++) {
s += std::to_string(hand_pose[i]);
s += ",";
}
s += "]";
return s;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "rosbridge_publisher_node.hpp"

#include <chrono>
#include <memory>

using namespace std::chrono_literals;

ROSbridgePublisherNode::ROSbridgePublisherNode()
: Node("rosbridge_publisher"),
rosbridge_publisher_(ROSbridgePublisherCore()) {

hand_pose_pub_ =
this->create_publisher<sample_msgs::msg::HandPose>("teleop", 10);
timer_ = this->create_wall_timer(
500ms, std::bind(&ROSbridgePublisherNode::timer_callback, this));
}

void ROSbridgePublisherNode::timer_callback() {
auto message = sample_msgs::msg::HandPose();
message.data = std::vector<float>(17);
RCLCPP_INFO(this->get_logger(), "Publishing: '%s'",
rosbridge_publisher_.hand_pose_to_string(message).c_str());
hand_pose_pub_->publish(message);
}

int main(int argc, char **argv) {
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<ROSbridgePublisherNode>());
rclcpp::shutdown();
return 0;
}
3 changes: 2 additions & 1 deletion autonomy/wato_msgs/sample_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ set(msg_files
msg/Filtered.msg
msg/FilteredArray.msg
msg/Unfiltered.msg
msg/Metadata.msg)
msg/Metadata.msg
msg/HandPose.msg)
rosidl_generate_interfaces(sample_msgs
${msg_files}
DEPENDENCIES std_msgs)
Expand Down
1 change: 1 addition & 0 deletions autonomy/wato_msgs/sample_msgs/msg/HandPose.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
float32[] data
Loading