Skip to content

Commit

Permalink
Merge pull request #6 from RobotMotorIntelligence:topic/pre-commit-in…
Browse files Browse the repository at this point in the history
…tegration

Pre commit integration
  • Loading branch information
cmastalli authored Jul 3, 2023
2 parents 7f1d06f + e0399a2 commit f5cb651
Show file tree
Hide file tree
Showing 23 changed files with 337 additions and 223 deletions.
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
ci:
autoupdate_branch: "master"
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args:
- --profile
- black
- --project
- crocoddyl_msgs
- --filter-files
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.6
hooks:
- id: clang-format
args: [-i, --style=file]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: check-json
- id: check-symlinks
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
109 changes: 56 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,72 +1,75 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
PROJECT(crocoddyl_msgs)
cmake_minimum_required(VERSION 3.1)
project(crocoddyl_msgs)

# Set up project properties
SET(PROJECT_NAME crocoddyl_msgs)
SET(PROJECT_DESCRIPTION "Crocoddyl ROS messages")
set(PROJECT_NAME crocoddyl_msgs)
set(PROJECT_DESCRIPTION "Crocoddyl ROS messages")

# Print initial message
MESSAGE(STATUS "${PROJECT_DESCRIPTION}, version ${PROJECT_VERSION}")
MESSAGE(STATUS "Copyright (C) 2020-2023 Heriot-Watt University, University of Oxford")
MESSAGE(STATUS "All rights reserved.")
MESSAGE(STATUS "Released under the BSD 3-Clause License.")
message(STATUS "${PROJECT_DESCRIPTION}, version ${PROJECT_VERSION}")
message(
STATUS "Copyright (C) 2020-2023 Heriot-Watt University, University of Oxford")
message(STATUS "All rights reserved.")
message(STATUS "Released under the BSD 3-Clause License.")

# Find required packages
FIND_PACKAGE(Eigen3 REQUIRED)
FIND_PACKAGE(pinocchio REQUIRED)
FIND_PACKAGE(catkin REQUIRED COMPONENTS
roscpp
std_msgs
whole_body_state_msgs
message_generation
realtime_tools
pybind11_catkin
)
find_package(Eigen3 REQUIRED)
find_package(pinocchio REQUIRED)
find_package(
catkin REQUIRED COMPONENTS roscpp std_msgs whole_body_state_msgs
message_generation realtime_tools pybind11_catkin)

# Define messages to be generated
ADD_MESSAGE_FILES(
DIRECTORY msg
add_message_files(
DIRECTORY
msg
FILES
TimeInterval.msg
State.msg
Control.msg
FeedbackGain.msg
SolverStatistics.msg
SolverTrajectory.msg
)
GENERATE_MESSAGES(
DEPENDENCIES
std_msgs
)
TimeInterval.msg
State.msg
Control.msg
FeedbackGain.msg
SolverStatistics.msg
SolverTrajectory.msg)
generate_messages(DEPENDENCIES std_msgs)

# Define catkin dependencies
CATKIN_PACKAGE(
INCLUDE_DIRS include
CATKIN_DEPENDS message_runtime std_msgs whole_body_state_msgs
DEPENDS
)
catkin_package(
INCLUDE_DIRS
include
CATKIN_DEPENDS
message_runtime
std_msgs
whole_body_state_msgs
DEPENDS)

# Define the Python modules
SET(${PROJECT_NAME}_PYBIND11_MODULE
crocoddyl_ros
)
set(${PROJECT_NAME}_PYBIND11_MODULE crocoddyl_ros)

IF(APPLE AND ${pybind11_catkin_VERSION} VERSION_LESS "2.10.3")
ADD_DEFINITIONS(-DCROCODDYL_MSG_DISABLE_PYBIND11_WARNINGS)
ENDIF()
if(APPLE AND ${pybind11_catkin_VERSION} VERSION_LESS "2.10.3")
add_definitions(-DCROCODDYL_MSG_DISABLE_PYBIND11_WARNINGS)
endif()

# Build the Python interface for the ROS publisher and subscriber
ADD_COMPILE_OPTIONS(-Wall -Wpedantic -Wextra -Wno-sign-conversion)
FOREACH(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})
PYBIND11_ADD_MODULE(${PYBIND11_MODULE} MODULE src/${PYBIND11_MODULE}.cpp)
TARGET_INCLUDE_DIRECTORIES(${PYBIND11_MODULE} PRIVATE include ${catkin_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PYBIND11_MODULE} PRIVATE ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${Boost_PYTHON_LIBRARY} pinocchio::pinocchio)
ADD_DEPENDENCIES(${PYBIND11_MODULE} ${crocoddyl_msgs_EXPORTED_TARGETS})
SET_TARGET_PROPERTIES(${PYBIND11_MODULE} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION})
INSTALL(TARGETS ${PYBIND11_MODULE} LIBRARY DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION})
ENDFOREACH(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})
add_compile_options(-Wall -Wpedantic -Wextra -Wno-sign-conversion)
foreach(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})
pybind11_add_module(${PYBIND11_MODULE} MODULE src/${PYBIND11_MODULE}.cpp)
target_include_directories(
${PYBIND11_MODULE} PRIVATE include ${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
target_link_libraries(
${PYBIND11_MODULE} PRIVATE ${catkin_LIBRARIES} ${Boost_LIBRARIES}
${Boost_PYTHON_LIBRARY} pinocchio::pinocchio)
add_dependencies(${PYBIND11_MODULE} ${crocoddyl_msgs_EXPORTED_TARGETS})
set_target_properties(
${PYBIND11_MODULE}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION})
install(TARGETS ${PYBIND11_MODULE}
LIBRARY DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION})
endforeach(PYBIND11_MODULE ${${PROJECT_NAME}_PYBIND11_MODULE})

# Install the include files
INSTALL(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})

ADD_SUBDIRECTORY(unittest)
add_subdirectory(unittest)
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Crocoddyl ROS messages
==============================================
# Crocoddyl ROS messages

## <img align="center" height="20" src="https://i.imgur.com/vAYeCzC.png"/> Introduction

Expand All @@ -10,17 +9,20 @@ Furthermore, the Python bindings of publishers and subscribers using roscpp help
## :penguin: Building

**crocoddyl_msgs** has the following dependencies:
* [std_msgs](http://wiki.ros.org/std_msgs)
* [whole_body_state_msgs](https://github.com/loco-3d/whole_body_state_msgs)
* [realtime_tools](http://wiki.ros.org/realtime_tools)
* [pybind11_catkin](https://github.com/wxmerkt/pybind11_catkin), wrapping [pybind11](https://pybind11.readthedocs.io/en/stable/basics.html) for use in ROS1
* [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page)
* [pinocchio](https://github.com/stack-of-tasks/pinocchio)

- [std_msgs](http://wiki.ros.org/std_msgs)
- [whole_body_state_msgs](https://github.com/loco-3d/whole_body_state_msgs)
- [realtime_tools](http://wiki.ros.org/realtime_tools)
- [pybind11_catkin](https://github.com/wxmerkt/pybind11_catkin), wrapping [pybind11](https://pybind11.readthedocs.io/en/stable/basics.html) for use in ROS1
- [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page)
- [pinocchio](https://github.com/stack-of-tasks/pinocchio)

To compile this catkin project you need to do:

cd your_ros_ws/
catkin build #catkin_make
```
cd your_ros_ws/
catkin build #catkin_make
```

## :copyright: Credits

Expand Down
12 changes: 5 additions & 7 deletions include/crocoddyl_msgs/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ static inline void toMsg(
throw std::invalid_argument("Expected a to be " + std::to_string(model.nv) +
" but received " + std::to_string(a.size()));
}
const std::size_t nv_root = model.joints[1].idx_q() == 0
? model.joints[1].nv()
: 0;
const std::size_t nv_root =
model.joints[1].idx_q() == 0 ? model.joints[1].nv() : 0;
const std::size_t njoints = model.nv - nv_root;
if (tau.size() != static_cast<int>(njoints) && tau.size() != 0) {
throw std::invalid_argument("Expected tau to be 0 or " +
Expand Down Expand Up @@ -463,9 +462,8 @@ fromMsg(const pinocchio::ModelTpl<double, Options, JointCollectionTpl> &model,
throw std::invalid_argument("Expected a to be " + std::to_string(model.nv) +
" but received " + std::to_string(v.size()));
}
const std::size_t nv_root = model.joints[1].idx_q() == 0
? model.joints[1].nv()
: 0;
const std::size_t nv_root =
model.joints[1].idx_q() == 0 ? model.joints[1].nv() : 0;
const std::size_t njoints = model.nv - nv_root;
if (tau.size() != static_cast<int>(njoints)) {
throw std::invalid_argument("Expected tau to be " +
Expand Down Expand Up @@ -577,4 +575,4 @@ fromMsg(const pinocchio::ModelTpl<double, Options, JointCollectionTpl> &model,

} // namespace crocoddyl_msgs

#endif // CONVERSIONS_H_
#endif // CONVERSIONS_H_
2 changes: 1 addition & 1 deletion include/crocoddyl_msgs/solver_statistics_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ class SolverStatisticsRosPublisher {

} // namespace crocoddyl_msgs

#endif // CROCODDYL_MSG_SOLVER_STATISTICS_PUBLISHER_H_
#endif // CROCODDYL_MSG_SOLVER_STATISTICS_PUBLISHER_H_
2 changes: 1 addition & 1 deletion include/crocoddyl_msgs/solver_statistics_subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ class SolverStatisticsRosSubscriber {

} // namespace crocoddyl_msgs

#endif // CROCODDYL_MSG_SOLVER_STATISTICS_SUBSCRIBER_H_
#endif // CROCODDYL_MSG_SOLVER_STATISTICS_SUBSCRIBER_H_
2 changes: 1 addition & 1 deletion include/crocoddyl_msgs/solver_trajectory_subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ class SolverTrajectoryRosSubscriber {

} // namespace crocoddyl_msgs

#endif // CROCODDYL_MSG_SOLVER_TRAJECTORY_SUBSCRIBER_H_
#endif // CROCODDYL_MSG_SOLVER_TRAJECTORY_SUBSCRIBER_H_
3 changes: 2 additions & 1 deletion include/crocoddyl_msgs/whole_body_state_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class WholeBodyStateRosPublisher {
pinocchio::Model &model,
const std::string &topic = "/crocoddyl/whole_body_state",
const std::string &frame = "odom")
: model_(model), data_(model), odom_frame_(frame), a_(Eigen::VectorXd::Zero(model.nv)) {
: model_(model), data_(model), odom_frame_(frame),
a_(Eigen::VectorXd::Zero(model.nv)) {
ros::NodeHandle n;
pub_.init(n, topic, 1);
pub_.msg_.header.frame_id = frame;
Expand Down
2 changes: 1 addition & 1 deletion include/crocoddyl_msgs/whole_body_state_subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ class WholeBodyStateRosSubscriber {

} // namespace crocoddyl_msgs

#endif // CROCODDYL_MSG_WHOLE_BODY_STATE_SUBSCRIBER_H_
#endif // CROCODDYL_MSG_WHOLE_BODY_STATE_SUBSCRIBER_H_
2 changes: 1 addition & 1 deletion include/crocoddyl_msgs/whole_body_trajectory_subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ class WholeBodyTrajectoryRosSubscriber {

} // namespace crocoddyl_msgs

#endif // CROCODDYL_MSG_WHOLE_BODY_TRAJECTORY_SUBSCRIBER_H_
#endif // CROCODDYL_MSG_WHOLE_BODY_TRAJECTORY_SUBSCRIBER_H_
2 changes: 1 addition & 1 deletion msg/Control.msg
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ uint8 parametrization
float64[] u

# This represents the feedback gain
crocoddyl_msgs/FeedbackGain gain
crocoddyl_msgs/FeedbackGain gain
4 changes: 2 additions & 2 deletions msg/FeedbackGain.msg
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
uint32 nx
uint32 nu

# This represents the entries of the matrix allocated by row order.
float64[] data
# This represents the entries of the matrix allocated by row order.
float64[] data
2 changes: 1 addition & 1 deletion msg/SolverStatistics.msg
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ float32 regularization
float32 step_length
float32 dynamic_feasibility
float32 equality_feasibility
float32 inequality_feasibility
float32 inequality_feasibility
2 changes: 1 addition & 1 deletion msg/SolverTrajectory.msg
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ crocoddyl_msgs/TimeInterval[] intervals
crocoddyl_msgs/State[] state_trajectory

# This represents the control for each interval
crocoddyl_msgs/Control[] control_trajectory
crocoddyl_msgs/Control[] control_trajectory
4 changes: 2 additions & 2 deletions msg/State.msg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# * the state's rate of change during the interval,
# in which the state contains the robot's posture and velocity.
#
# The initial state and its rate of change allow us to compute the
# The initial state and its rate of change allow us to compute the
# state in a desired time.
#
# The order of the state is designed to be consistent with the URDF.
Expand All @@ -16,4 +16,4 @@
float64[] x

# This represents the state's rate of change during the interval
float64[] dx
float64[] dx
2 changes: 1 addition & 1 deletion msg/TimeInterval.msg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
float64 time

# This represents the duration of the interval
float64 duration
float64 duration
15 changes: 13 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>crocoddyl_msgs</name>
<version>0.0.1</version>
<description>
Message structures needed to interact with Crocoddyl solvers, inputs and outputs
Message structures needed to interact with Crocoddyl solvers, inputs and outputs.
</description>

<maintainer email="[email protected]">Carlos Mastalli</maintainer>
Expand All @@ -13,6 +13,7 @@

<buildtool_depend>catkin</buildtool_depend>

<!-- build and runtime dependencies -->
<depend>roscpp</depend>
<depend>eigen</depend>
<depend>std_msgs</depend>
Expand All @@ -21,13 +22,23 @@
<depend>pybind11_catkin</depend>
<depend>pinocchio</depend>

<!-- build dependencies -->
<build_depend>rospy</build_depend>
<build_depend>message_generation</build_depend>

<!-- runtime dependencies -->
<exec_depend>rospy</exec_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-numpy</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-numpy</exec_depend>

<member_of_group>rosidl_interface_packages</member_of_group>

<test_depend>rostest</test_depend>
</package>

<export>
<!-- This suffers from a bug in catkin, cf.: https://github.com/ros/catkin/issues/1170 -->
<build_type condition="$ROS_VERSION == 1">catkin</build_type>
<build_type condition="$ROS_VERSION == 2">ament_cmake</build_type>
</export>
</package>
2 changes: 1 addition & 1 deletion src/crocoddyl_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,4 @@ PYBIND11_MODULE(crocoddyl_ros, m) {
"friction\n"
"coefficients.")
.def("has_new_msg", &WholeBodyTrajectoryRosSubscriber::has_new_msg);
}
}
Loading

0 comments on commit f5cb651

Please sign in to comment.