Skip to content

freyja_examples: Ported temporal_provider example #14

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

Open
wants to merge 2 commits into
base: ros2-devel
Choose a base branch
from
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
55 changes: 23 additions & 32 deletions freyja_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)
project(freyja_examples)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3" )

## 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
message_generation
roscpp
freyja_msgs
std_msgs
)

add_compile_options( -std=c++14 -O3 -ffast-math -Wall )

catkin_package(
# INCLUDE_DIRS include
# LIBRARIES trajectory_provider
CATKIN_DEPENDS geometry_msgs message_generation message_runtime roscpp std_msgs
# DEPENDS system_lib
)
find_package(ament_cmake REQUIRED)

###########
## Build ##
###########
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(freyja_msgs REQUIRED)

include_directories(include)
include_directories(
${catkin_INCLUDE_DIRS}

add_executable(temporal_provider src/temporal_provider.cpp)

target_include_directories( temporal_provider PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

ament_target_dependencies( temporal_provider
rclcpp
freyja_msgs
std_msgs
)

# simple trajectory provider
add_executable(temporal_provider_node src/temporal_provider.cpp)
add_dependencies(temporal_provider_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
install(TARGETS
temporal_provider
DESTINATION lib/${PROJECT_NAME})

target_link_libraries(temporal_provider_node
${catkin_LIBRARIES}
)

ament_package()
55 changes: 55 additions & 0 deletions freyja_examples/include/temporal_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Provides a trajectory for the vehicle to follow.
EXAMPLE FILE; ONLY FOR SUPPORT.
Whatever you do here, output a time-based continuous function to follow.
This node should generate a 7 vector: [pn pe pd vn ve vd yaw]' for the vehicle
to follow. The controller currently listens to this reference trajectory
and updates its knowledge of the "latest" reference point.

-- aj / 23rd Nov, 2017.
*/

#include <chrono>
#include <cmath>
#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/u_int8.hpp"
#include "freyja_msgs/msg/reference_state.hpp"

typedef freyja_msgs::msg::ReferenceState TrajRef;

#define DEG2RAD(D) ((D)*3.1415326/180.0)

using std::placeholders::_1;
using namespace std::chrono_literals;

rclcpp::Time init_time;
std::string traj_type;
int agg_level;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three are unused, I think?


class Temporal_Traj : public rclcpp::Node
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be better to remove the _ in the class name. It is redundant with this case-style, and also will maintain consistency.

{
TrajRef ref_state;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider naming class member variables with an _ postfix: ref_state_

rclcpp::Time init_time;

std::string traj_type;
int agg_level;

public:
Temporal_Traj();

rclcpp::Subscription<std_msgs::msg::UInt8>::SharedPtr time_reset_sub_;
void timer_reset_cb( const std_msgs::msg::UInt8::SharedPtr msg );

rclcpp::Publisher<TrajRef>::SharedPtr traj_pub_;

rclcpp::TimerBase::SharedPtr traj_update_timer_;
void traj_update_cb();

TrajRef getHoverReference( rclcpp::Duration cur_time );
TrajRef getCircleReference( rclcpp::Duration cur_time, const int agg_level);
TrajRef getDefaultReference( rclcpp::Duration cur_time );
TrajRef getLemiscateReference( rclcpp::Duration cur_time, const int agg_level);

};

36 changes: 11 additions & 25 deletions freyja_examples/package.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
<?xml version="1.0"?>
<package>
<package format="3">
<name>freyja_examples</name>
<version>0.0.0</version>
<description>The examples package showing use cases</description>

<!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="aj@todo.todo">aj</maintainer>

<description>ROS2 Trajectory Examples</description>
<maintainer email="hw527@cam.ac.uk">Peter Woo</maintainer>
<license>GPLv3</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<buildtool_depend>catkin</buildtool_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>freyja_msgs</build_depend>
<build_depend>std_msgs</build_depend>

<run_depend>geometry_msgs</run_depend>
<run_depend>message_runtime</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>message_generation</run_depend>


<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here -->
<depend>rclcpp</depend>
<depend>std_msgs</depend>
<depend>std_srvs</depend>
<depend>freyja_msgs</depend>

<export>
<build_type>ament_cmake</build_type>
</export>

</package>
Loading