Skip to content

Commit 3fc45a3

Browse files
committed
created forward jacobian determinant node
1 parent 82e045b commit 3fc45a3

File tree

5 files changed

+119
-1
lines changed

5 files changed

+119
-1
lines changed

src/pr_modelling/CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,26 @@ ament_target_dependencies(ang_ots
195195
"pr_lib")
196196

197197
rclcpp_components_register_nodes(ang_ots "pr_modelling::AngOTS")
198-
set(node_plugins "${node_plugins}pr_modelling::StatePublisher;$<TARGET_FILE:ang_ots>\n")
198+
set(node_plugins "${node_plugins}pr_modelling::AngOTS;$<TARGET_FILE:ang_ots>\n")
199+
200+
201+
### Forward Jacobian node ###
202+
203+
add_library(for_jac SHARED
204+
src/for_jac.cpp)
205+
206+
target_compile_definitions(for_jac
207+
PRIVATE "COMPOSITION_BUILDING_DLL")
208+
209+
ament_target_dependencies(for_jac
210+
"rclcpp"
211+
"rclcpp_components"
212+
"pr_msgs"
213+
"pr_lib")
214+
215+
rclcpp_components_register_nodes(for_jac "pr_modelling::ForwardJacobian")
216+
set(node_plugins "${node_plugins}pr_modelling::ForwardJacobian;$<TARGET_FILE:for_jac>\n")
217+
199218

200219

201220
### Installation ###
@@ -209,6 +228,7 @@ install(TARGETS
209228
q_grav
210229
state_publisher
211230
ang_ots
231+
for_jac
212232
ARCHIVE DESTINATION lib
213233
LIBRARY DESTINATION lib
214234
RUNTIME DESTINATION bin)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef PR_MODELLING__FOR_JAC_HPP_
2+
#define PR_MODELLING__FOR_JAC_HPP_
3+
4+
#include <vector>
5+
6+
#include "rclcpp/rclcpp.hpp"
7+
8+
#include "pr_msgs/msg/pr_array_h.hpp"
9+
#include "pr_msgs/msg/pr_float_h.hpp"
10+
11+
#include "pr_lib/pr_model.hpp"
12+
13+
namespace pr_modelling
14+
{
15+
class ForwardJacobian : public rclcpp::Node
16+
{
17+
public:
18+
//PR_MODELLING_PUBLIC
19+
explicit ForwardJacobian(const rclcpp::NodeOptions & options);
20+
21+
protected:
22+
void topic_callback(const pr_msgs::msg::PRArrayH::SharedPtr x_msg);
23+
24+
private:
25+
rclcpp::Subscription<pr_msgs::msg::PRArrayH>::SharedPtr subscription_;
26+
rclcpp::Publisher<pr_msgs::msg::PRFloatH>::SharedPtr publisher_;
27+
28+
Eigen::Matrix<double, 4, 4> ForJac = Eigen::Matrix<double, 4, 4>::Zero();
29+
std::vector<double> robot_params;
30+
};
31+
}
32+
33+
#endif // PR_MODELLING__IND_JAC_HPP_

src/pr_modelling/src/for_jac.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "pr_modelling/for_jac.hpp"
2+
3+
#include <chrono>
4+
#include <memory>
5+
#include <utility>
6+
#include <array>
7+
#include <vector>
8+
9+
#include "pr_lib/pr_model.hpp"
10+
11+
using std::placeholders::_1;
12+
13+
namespace pr_modelling
14+
{
15+
/**** FORWARD JACOBIAN COMPONENT ****/
16+
ForwardJacobian::ForwardJacobian(const rclcpp::NodeOptions & options)
17+
: Node("for_jac", options)
18+
{
19+
//Parameter declaration
20+
this->declare_parameter<std::vector<double>>(
21+
"robot_config_params",
22+
{0.4, 0.4, 0.4, 0.15, 90*(M_PI/180), 45*(M_PI/180), 0.3, 0.3, 0.3, 50*(M_PI/180), 90*(M_PI/180)});
23+
24+
this->get_parameter("robot_config_params", robot_params);
25+
26+
subscription_ = this->create_subscription<pr_msgs::msg::PRArrayH>(
27+
"x_coord",
28+
10,
29+
std::bind(&ForwardJacobian::topic_callback, this, _1));
30+
31+
publisher_ = this->create_publisher<pr_msgs::msg::PRFloatH>(
32+
"for_jac_det",
33+
1);
34+
}
35+
36+
void ForwardJacobian::topic_callback(const pr_msgs::msg::PRArrayH::SharedPtr x_msg)
37+
{
38+
PRModel::ForwardJacobian(ForJac, x_msg->data, robot_params);
39+
40+
double for_jac_det = ForJac.determinant();
41+
42+
auto for_jac_det_msg = pr_msgs::msg::PRFloatH();
43+
44+
for_jac_det_msg.data = for_jac_det;
45+
for_jac_det_msg.current_time = this->get_clock()->now();
46+
for_jac_det_msg.header.stamp = x_msg->header.stamp;
47+
for_jac_det_msg.header.frame_id = x_msg->header.frame_id;
48+
49+
publisher_->publish(for_jac_det_msg);
50+
}
51+
}
52+
53+
#include "rclcpp_components/register_node_macro.hpp"
54+
55+
// Register the component with class_loader.
56+
// This acts as a sort of entry point, allowing the component to be discoverable when its library
57+
// is being loaded into a running process.
58+
RCLCPP_COMPONENTS_REGISTER_NODE(pr_modelling::ForwardJacobian)

src/pr_msgs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ rosidl_generate_interfaces(${PROJECT_NAME}
4545
"msg/PRMocap.msg"
4646
"msg/PRState.msg"
4747
"msg/PROTS.msg"
48+
"msg/PRFloatH.msg"
4849
"srv/Trajectory.srv"
4950
DEPENDENCIES builtin_interfaces std_msgs
5051
)

src/pr_msgs/msg/PRFloatH.msg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Message to communicate a float number with a header and time
2+
3+
std_msgs/Header header
4+
builtin_interfaces/Time current_time
5+
6+
float64 data

0 commit comments

Comments
 (0)