31
31
#include < ignition/gazebo/components/JointVelocity.hh>
32
32
#include < ignition/gazebo/components/JointVelocityCmd.hh>
33
33
#include < ignition/gazebo/components/JointAxis.hh>
34
+ #include < ignition/gazebo/components/JointType.hh>
35
+ #include < ignition/gazebo/components/Joint.hh>
34
36
35
37
#include < ignition/gazebo/components/LinearAcceleration.hh>
36
38
#include < ignition/gazebo/components/Name.hh>
46
48
#include < iostream>
47
49
48
50
#include < hardware_interface/hardware_info.hpp>
51
+ #include < normApi.h>
49
52
50
53
struct jointData
51
54
{
@@ -241,11 +244,6 @@ bool IgnitionSystem::initSim(
241
244
_ecm.CreateComponent (simjoint, ignition::gazebo::components::JointForce ());
242
245
}
243
246
244
- // init PID
245
- // assuming every joint has axis
246
- const auto * jointAxis =
247
- this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointAxis>(
248
- this ->dataPtr ->joints_ [j].sim_joint );
249
247
// PID parameters
250
248
double p_gain =
251
249
(hardware_info.joints [j].parameters .find (" p" ) ==
@@ -752,10 +750,6 @@ hardware_interface::return_type IgnitionSystem::write(
752
750
error, std::chrono::duration<double >(
753
751
period.to_chrono <std::chrono::nanoseconds>()));
754
752
755
- igndbg << " target_force ( joint [" <<
756
- this ->dataPtr ->joints_ [i].name << " ] ) = " << target_force <<
757
- " \n " ;
758
-
759
753
auto forceCmd =
760
754
this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointForceCmd>(
761
755
this ->dataPtr ->joints_ [i].sim_joint );
@@ -794,6 +788,10 @@ hardware_interface::return_type IgnitionSystem::write(
794
788
this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointAxis>(
795
789
this ->dataPtr ->joints_ [mimic_joint.joint_index ].sim_joint );
796
790
791
+ const auto * jointAxisMimicked =
792
+ this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointAxis>(
793
+ this ->dataPtr ->joints_ [mimic_joint.mimicked_joint_index ].sim_joint );
794
+
797
795
if (mimic_interface == " position" ) {
798
796
// Get the joint position
799
797
double position_mimicked_joint =
@@ -806,33 +804,33 @@ hardware_interface::return_type IgnitionSystem::write(
806
804
double position_error =
807
805
position_mimic_joint - std::clamp (
808
806
position_mimicked_joint * mimic_joint.multiplier ,
809
- jointAxis ->Data ().Lower (), jointAxis ->Data ().Upper ());
807
+ jointAxisMimicked ->Data ().Lower (), jointAxisMimicked ->Data ().Upper ());
810
808
811
809
position_error = copysign (1.0 , position_error) * std::clamp (
812
810
std::abs (
813
- position_error), 0.0 , std::abs (
814
- jointAxis->Data ().Upper () - jointAxis->Data ().Lower ()));
811
+ position_error), 0.0 , std::abs (jointAxisMimicked->Data ().Upper () - jointAxisMimicked->Data ().Lower ()));
815
812
816
813
// calculate target force/torque
817
- double target_force = this ->dataPtr ->joints_ [mimic_joint.joint_index ].pid .Update (
814
+ double target_vel = this ->dataPtr ->joints_ [mimic_joint.joint_index ].pid .Update (
818
815
position_error,
819
816
std::chrono::duration<double >(period.to_chrono <std::chrono::nanoseconds>()));
820
817
821
- igndbg << " target_force ( mimic joint [" <<
822
- this ->dataPtr ->joints_ [mimic_joint.joint_index ].name << " ] ) = " << target_force <<
823
- " \n " ;
824
-
825
- auto forceCmd =
826
- this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointForceCmd>(
818
+ auto velCmd =
819
+ this ->dataPtr ->ecm ->Component <ignition::gazebo::components::JointVelocityCmd>(
827
820
this ->dataPtr ->joints_ [mimic_joint.joint_index ].sim_joint );
828
821
829
- if (forceCmd == nullptr ) {
822
+ // igndbg<<"position_error ["<<this->dataPtr->joints_[mimic_joint.joint_index].name<<"] = "<<position_error<<"\n";
823
+ // igndbg<<"target_force ["<<this->dataPtr->joints_[mimic_joint.joint_index].name<<"] = "<<target_force<<"\n";
824
+
825
+
826
+ if (velCmd == nullptr ) {
830
827
this ->dataPtr ->ecm ->CreateComponent (
831
828
this ->dataPtr ->joints_ [mimic_joint.joint_index ].sim_joint ,
832
- ignition::gazebo::components::JointForceCmd ({0 }));
829
+ ignition::gazebo::components::JointVelocityCmd ({0 }));
830
+
833
831
} else {
834
- *forceCmd = ignition::gazebo::components::JointForceCmd (
835
- {target_force });
832
+ *velCmd = ignition::gazebo::components::JointVelocityCmd (
833
+ {target_vel });
836
834
}
837
835
}/*
838
836
if (mimic_interface == "velocity") {
0 commit comments