77#include " control/control_utilities.hh"
88#include " control/jet_vane_mapper.hh"
99#include " control/servo_interface.hh"
10+
1011#include " filtering/pose_message.hh"
12+ #include " filtering/yaml_matrix.hh"
13+
1114#include " infrastructure/balsa_queue/bq_main_macro.hh"
1215#include " infrastructure/engine/turbine_state_message.hh"
1316
14- #include " third_party/experiments/estimation/time_point.hh"
15-
1617namespace jet {
1718namespace control {
1819
1920namespace {
2021
21- estimation::TimePoint to_time_point (const Timestamp& ts) {
22- const auto epoch_offset = std::chrono::nanoseconds (uint64_t (ts));
23- const estimation::TimePoint time_point = estimation::TimePoint{} + epoch_offset;
24- return time_point;
25- }
26-
22+ /*
2723jcc::Vec3 sigmoid(const jcc::Vec3& v) {
2824 const double v_nrm = v.norm();
2925
3026 const double interp_value = (1.0 / (1.0 + std::exp(-v_nrm)));
3127
3228 return interp_value * v.normalized();
3329}
30+ */
3431
35- QuadraframeStatus generate_control (const SO3& world_from_target, const Pose& pose, const JetStatus& jet_status) {
32+ QuadraframeStatus generate_control (const SO3& world_from_target,
33+ const Pose& pose,
34+ const JetStatus& jet_status,
35+ const GainConfig& cfg) {
3636 JetVaneMapper mapper_;
3737
38- const MatNd<3 , 3 > K = jcc::Vec3 (0.3 , 0.3 , 0.4 ).asDiagonal ();
38+ const jcc::Vec3 w_jet_frame = pose.world_from_jet .inverse () * pose.w_world_frame ;
39+
40+ const MatNd<3 , 3 > Kp = cfg.k_proportional .asDiagonal ();
41+ const MatNd<3 , 3 > Kd = cfg.k_derivative .asDiagonal ();
3942
4043 //
4144 // Compute the current expected jet force (All servos zero'd)
@@ -53,7 +56,7 @@ QuadraframeStatus generate_control(const SO3& world_from_target, const Pose& pos
5356 const jcc::Vec3 desired_force_jet_frame = wrench_for_zero.force_N ;
5457
5558 const SO3 target_from_jet = world_from_target.inverse () * pose.world_from_jet .so3 ();
56- const jcc::Vec3 desired_torque_jet_frame = -K * target_from_jet.log ();
59+ const jcc::Vec3 desired_torque_jet_frame = -(Kp * target_from_jet.log ()) + -(Kd * w_jet_frame );
5760
5861 Wrench target_wrench;
5962 target_wrench.torque_Nm = desired_torque_jet_frame;
@@ -99,6 +102,9 @@ void ControllerBq::init(const Config& config) {
99102 std::cout << " Subscribing Turbine State" << std::endl;
100103 turbine_state_sub_ = make_subscriber (" turbine_state" );
101104
105+ read_matrix (config[" k_proportional" ], gain_cfg_.k_proportional );
106+ read_matrix (config[" k_derivative" ], gain_cfg_.k_derivative );
107+
102108 std::cout << " Controller starting" << std::endl;
103109}
104110
@@ -125,7 +131,7 @@ void ControllerBq::loop() {
125131
126132 if (got_pose_msg && got_turbine_status_) {
127133 const Pose pose = pose_msg.to_pose ();
128- const auto target_qframe_status = generate_control (target_from_world, pose, jet_status_);
134+ const auto target_qframe_status = generate_control (target_from_world, pose, jet_status_, gain_cfg_ );
129135 SetServoMessage servo_message = create_servo_command (target_qframe_status);
130136 servo_pub_->publish (servo_message);
131137 }
0 commit comments