43
43
44
44
#include < ignition/transport/Node.hh>
45
45
46
+ #include < iostream>
46
47
47
48
#include < hardware_interface/hardware_info.hpp>
48
49
@@ -246,19 +247,47 @@ bool IgnitionSystem::initSim(
246
247
this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointAxis>(
247
248
this ->dataPtr ->joints_ [j].sim_joint );
248
249
// PID parameters
249
- double p_gain = 1000.0 ;
250
- double i_gain = 0.0 ;
251
- double d_gain = 0.0 ;
250
+ double p_gain =
251
+ (hardware_info.joints [j].parameters .find (" p" ) ==
252
+ hardware_info.joints [j].parameters .end () ) ? 100.0 : stod (
253
+ hardware_info.joints [j].parameters .at (
254
+ " p" ));
255
+ double i_gain =
256
+ (hardware_info.joints [j].parameters .find (" i" ) ==
257
+ hardware_info.joints [j].parameters .end () ) ? 0.0 : stod (
258
+ hardware_info.joints [j].parameters .at (
259
+ " i" ));
260
+ double d_gain =
261
+ (hardware_info.joints [j].parameters .find (" d" ) ==
262
+ hardware_info.joints [j].parameters .end () ) ? 5.0 : stod (
263
+ hardware_info.joints [j].parameters .at (
264
+ " d" ));
252
265
// set integral max and min component to 50 percent of the max effort
253
- double iMax = std::isnan (jointAxis->Data ().Effort ()) ? 500.0 : jointAxis->Data ().Effort () *
254
- 0.5 ;
255
- double iMin = std::isnan (jointAxis->Data ().Effort ()) ? 500.0 : -jointAxis->Data ().Effort () *
256
- 0.5 ;
266
+ double iMax =
267
+ (hardware_info.joints [j].parameters .find (" iMax" ) ==
268
+ hardware_info.joints [j].parameters .end () ) ? 500.0 : stod (
269
+ hardware_info.joints [j].parameters .at (
270
+ " iMax" ));
271
+ double iMin =
272
+ (hardware_info.joints [j].parameters .find (" iMin" ) ==
273
+ hardware_info.joints [j].parameters .end () ) ? -500 : stod (
274
+ hardware_info.joints [j].parameters .at (
275
+ " iMin" ));
257
276
double cmdMax =
258
- std::isnan (jointAxis->Data ().Effort ()) ? 1000.0 : jointAxis->Data ().Effort ();
277
+ (hardware_info.joints [j].parameters .find (" cmdMax" ) ==
278
+ hardware_info.joints [j].parameters .end () ) ? 1000.0 : stod (
279
+ hardware_info.joints [j].parameters .at (
280
+ " cmdMax" ));
259
281
double cmdMin =
260
- std::isnan (jointAxis->Data ().Effort ()) ? -1000.0 : -jointAxis->Data ().Effort ();
261
- double cmdOffset = 0.0 ;
282
+ (hardware_info.joints [j].parameters .find (" cmdMin" ) ==
283
+ hardware_info.joints [j].parameters .end () ) ? -1000.0 : stod (
284
+ hardware_info.joints [j].parameters .at (
285
+ " cmdMin" ));
286
+ double cmdOffset =
287
+ (hardware_info.joints [j].parameters .find (" cmdOffset" ) ==
288
+ hardware_info.joints [j].parameters .end () ) ? 0.0 : stod (
289
+ hardware_info.joints [j].parameters .at (
290
+ " cmdOffset" ));
262
291
263
292
param_vec.push_back (rclcpp::Parameter{" gains." + joint_name + " .p" , p_gain});
264
293
param_vec.push_back (rclcpp::Parameter{" gains." + joint_name + " .i" , i_gain});
@@ -665,6 +694,7 @@ hardware_interface::return_type IgnitionSystem::write(
665
694
params_ = param_listener_->get_params ();
666
695
667
696
for (unsigned int i = 0 ; i < this ->dataPtr ->joints_ .size (); ++i) {
697
+
668
698
// assuming every joint has axis
669
699
const auto * jointAxis =
670
700
this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointAxis>(
@@ -709,7 +739,6 @@ hardware_interface::return_type IgnitionSystem::write(
709
739
double error = this ->dataPtr ->joints_ [i].joint_position - std::clamp (
710
740
this ->dataPtr ->joints_ [i].joint_position_cmd , jointAxis->Data ().Lower (),
711
741
jointAxis->Data ().Upper ());
712
-
713
742
error =
714
743
copysign (
715
744
1.0 ,
@@ -723,6 +752,10 @@ hardware_interface::return_type IgnitionSystem::write(
723
752
error, std::chrono::duration<double >(
724
753
period.to_chrono <std::chrono::nanoseconds>()));
725
754
755
+ igndbg << " target_force ( joint [" <<
756
+ this ->dataPtr ->joints_ [i].name << " ] ) = " << target_force <<
757
+ " \n " ;
758
+
726
759
auto forceCmd =
727
760
this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointForceCmd>(
728
761
this ->dataPtr ->joints_ [i].sim_joint );
@@ -749,25 +782,10 @@ hardware_interface::return_type IgnitionSystem::write(
749
782
*jointEffortCmd = ignition::gazebo::components::JointForceCmd (
750
783
{this ->dataPtr ->joints_ [i].joint_effort_cmd });
751
784
}
752
- } /* else {
753
- // Fallback case is a velocity command of zero
754
- double target_vel = 0.0;
755
- auto vel =
756
- this->dataPtr->ecm->Component<ignition::gazebo::components::JointVelocityCmd>(
757
- this->dataPtr->joints_[i].sim_joint);
758
-
759
- if (vel == nullptr) {
760
- this->dataPtr->ecm->CreateComponent(
761
- this->dataPtr->joints_[i].sim_joint,
762
- ignition::gazebo::components::JointVelocityCmd({target_vel}));
763
- } else if (!vel->Data().empty()) {
764
- vel->Data()[0] = target_vel;
765
- } else if (!vel->Data().empty()) {
766
- vel->Data()[0] = target_vel;
767
- }
768
- }*/
785
+ }
769
786
}
770
787
788
+
771
789
// set values of all mimic joints with respect to mimicked joint
772
790
for (const auto & mimic_joint : this ->dataPtr ->mimic_joints_ ) {
773
791
for (const auto & mimic_interface : mimic_joint.interfaces_to_mimic ) {
@@ -800,6 +818,10 @@ hardware_interface::return_type IgnitionSystem::write(
800
818
position_error,
801
819
std::chrono::duration<double >(period.to_chrono <std::chrono::nanoseconds>()));
802
820
821
+ igndbg << " target_force ( mimic joint [" <<
822
+ this ->dataPtr ->joints_ [mimic_joint.joint_index ].name << " ] ) = " << target_force <<
823
+ " \n " ;
824
+
803
825
auto forceCmd =
804
826
this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointForceCmd>(
805
827
this ->dataPtr ->joints_ [mimic_joint.joint_index ].sim_joint );
0 commit comments