4848typedef Eigen::Matrix<float , 7 , 1 > Vector7f;
4949typedef Eigen::Matrix<float , 6 , 1 > Vector6f;
5050
51+ struct ConveyorBeltState {
52+ bool ctrlModeConveyorBelt;
53+ bool isDisturbTarget;
54+ int modeConveyorBelt;
55+ int nominalSpeedConveyorBelt;
56+ int magniturePertConveyorBelt;
57+ };
58+
5159class RosDualArmCommunication {
5260private:
5361 // ---- ROS
5462 ros::NodeHandle nh_;// Ros node handle
5563 ros::Rate loopRate_;// Ros loop rate [Hz]
64+ double frequency_;
5665
5766 bool isSimulation_ = true ;
5867 std::vector<float > objectDimVect_;
@@ -93,10 +102,19 @@ class RosDualArmCommunication {
93102 // params update
94103 std::string dsDampingTopicParams_[NB_ROBOTS ];
95104
105+ // ---- Conveyor belt control
106+ bool ctrlModeConveyorBelt_;
107+ bool isDisturbTarget_;
108+ int modeConveyorBelt_;
109+ int nominalSpeedConveyorBelt_;
110+ int magniturePertConveyorBelt_;
111+ int desSpeedConveyorBelt_;
112+
96113public:
97114 // For controllers
98115 float firstEigenPassiveDamping_[NB_ROBOTS ];
99- Eigen::Vector3f eePose_[NB_ROBOTS ], objectPose_, targetPose_, eeVelLin_[NB_ROBOTS ], eeVelAng_[NB_ROBOTS ], robotBasePos_[NB_ROBOTS ];
116+ Eigen::Vector3f eePose_[NB_ROBOTS ], objectPose_, targetPose_, eeVelLin_[NB_ROBOTS ], eeVelAng_[NB_ROBOTS ],
117+ robotBasePos_[NB_ROBOTS ];
100118 Eigen::Vector4f eeOrientation_[NB_ROBOTS ], objectOrientation_, targetOrientation_, robotBaseOrientation_[NB_ROBOTS ];
101119 Vector7f jointPosition_[NB_ROBOTS ], jointVelocity_[NB_ROBOTS ], jointTorques_[NB_ROBOTS ];
102120 Eigen::Matrix<float , 6 , 1 > robotWrench_[NB_ROBOTS ];
@@ -105,7 +123,7 @@ class RosDualArmCommunication {
105123 // Robot ID: left or right
106124 enum Robot { LEFT = 0 , RIGHT = 1 };
107125
108- RosDualArmCommunication (ros::NodeHandle& n, double frequency) : nh_(n), loopRate_(frequency){};
126+ RosDualArmCommunication (ros::NodeHandle& n, double frequency) : nh_(n), loopRate_(frequency), frequency_(frequency) {};
109127
110128 ~RosDualArmCommunication (){};
111129
@@ -126,11 +144,9 @@ class RosDualArmCommunication {
126144 initDampingTopicCtrl ();
127145 initRosSubscribers ();
128146 initRosPublisher ();
147+ initConveyorBelt ();
129148
130- for (int k = 0 ; k < NB_ROBOTS ; k++) {
131- firstEigenPassiveDamping_[k] = 1 .0f ;
132- }
133-
149+ for (int k = 0 ; k < NB_ROBOTS ; k++) { firstEigenPassiveDamping_[k] = 1 .0f ; }
134150
135151 if (nh_.ok ()) {
136152 // Wait for poses being published
@@ -387,17 +403,6 @@ class RosDualArmCommunication {
387403 pubDistAttractorEE_[LEFT ] = nh_.advertise <std_msgs::Float64>(topicDistAttractorEE[LEFT ], 1 );
388404 pubDistAttractorEE_[RIGHT ] = nh_.advertise <std_msgs::Float64>(topicDistAttractorEE[RIGHT ], 1 );
389405
390- // Conveyor Belt
391- std::string topicConveyorBeltMode, topicConveyorBeltSpeed;
392- while (!nh_.getParam (nh_.getNamespace () + " /conveyor_belt/desired_mode" , topicConveyorBeltMode)) {
393- ROS_INFO (" Waitinng for param: conveyor_belt/desired_mode " );
394- }
395- while (!nh_.getParam (nh_.getNamespace () + " /conveyor_belt/desired_speed" , topicConveyorBeltSpeed)) {
396- ROS_INFO (" Waitinng for param: conveyor_belt/desired_speed " );
397- }
398- pubConveyorBeltMode_ = nh_.advertise <std_msgs::Int32>(topicConveyorBeltMode, 1 );
399- pubConveyorBeltSpeed_ = nh_.advertise <std_msgs::Int32>(topicConveyorBeltSpeed, 1 );
400-
401406 return true ;
402407 }
403408
@@ -521,11 +526,6 @@ class RosDualArmCommunication {
521526 msgFnormMoment.torque .z = -appliedWrench[k](5 );
522527 pubAppliedFNormMoment_[k].publish (msgFnormMoment);
523528 }
524-
525- // // Send speed command to the conveyor belt TODO
526- // std_msgs::Int32 speedMsgConveyorBelt;
527- // speedMsgConveyorBelt.data = desSpeedConveyorBelt_;
528- // if (ctrlModeConveyorBelt_ && (fmod(cycleCount_, 30) == 0)) { pubConveyorBeltSpeed_.publish(speedMsgConveyorBelt); }
529529 }
530530
531531 bool initDampingTopicCtrl () {
@@ -568,6 +568,36 @@ class RosDualArmCommunication {
568568 return true ;
569569 }
570570
571+ bool initConveyorBelt () {
572+ // Publisher
573+ std::string topicConveyorBeltMode, topicConveyorBeltSpeed;
574+ while (!nh_.getParam (" conveyor_belt/desired_mode" , topicConveyorBeltMode)) {
575+ ROS_INFO (" Waitinng for param: conveyor_belt/desired_mode " );
576+ }
577+ while (!nh_.getParam (" conveyor_belt/desired_speed" , topicConveyorBeltSpeed)) {
578+ ROS_INFO (" Waitinng for param: conveyor_belt/desired_speed " );
579+ }
580+ pubConveyorBeltMode_ = nh_.advertise <std_msgs::Int32>(topicConveyorBeltMode, 1 );
581+ pubConveyorBeltSpeed_ = nh_.advertise <std_msgs::Int32>(topicConveyorBeltSpeed, 1 );
582+
583+ // Params
584+ while (!nh_.getParam (" conveyor_belt/control_mode" , ctrlModeConveyorBelt_)) {
585+ ROS_INFO (" Waitinng for param: conveyor_belt/control_mode " );
586+ }
587+ while (!nh_.getParam (" conveyor_belt/nominal_speed" , nominalSpeedConveyorBelt_)) {
588+ ROS_INFO (" Waitinng for param: conveyor_belt/nominal_speed" );
589+ }
590+ while (!nh_.getParam (" conveyor_belt/magnitude_perturbation" , magniturePertConveyorBelt_)) {
591+ ROS_INFO (" Waitinng for param: conveyor_belt/magnitude_perturbation" );
592+ }
593+ desSpeedConveyorBelt_ = nominalSpeedConveyorBelt_;
594+
595+ modeConveyorBelt_ = 0 ;
596+ isDisturbTarget_ = false ;
597+
598+ return true ;
599+ }
600+
571601 // ---- Callback functions
572602
573603 void objectPoseCallback (const geometry_msgs::Pose::ConstPtr& msg) {
@@ -639,4 +669,51 @@ class RosDualArmCommunication {
639669 firstEigenPassiveDamping_[RIGHT ] = paramValues[0 ];
640670 if (firstEigenPassiveDamping_[RIGHT ] < FLT_EPSILON ) { firstEigenPassiveDamping_[RIGHT ] = 150 .0f ; }
641671 }
672+
673+ // ---- Conveyor belt control
674+ ConveyorBeltState getConveyorBeltStatus () {
675+ ConveyorBeltState conveyorBeltState;
676+ conveyorBeltState.ctrlModeConveyorBelt = ctrlModeConveyorBelt_;
677+ conveyorBeltState.modeConveyorBelt = modeConveyorBelt_;
678+
679+ conveyorBeltState.nominalSpeedConveyorBelt = nominalSpeedConveyorBelt_;
680+ conveyorBeltState.magniturePertConveyorBelt = magniturePertConveyorBelt_;
681+ conveyorBeltState.isDisturbTarget = isDisturbTarget_;
682+
683+ return conveyorBeltState;
684+ }
685+
686+ void updateConveyorBeltStatus (ConveyorBeltState conveyorBeltState) {
687+ nominalSpeedConveyorBelt_ = conveyorBeltState.nominalSpeedConveyorBelt ;
688+ magniturePertConveyorBelt_ = conveyorBeltState.magniturePertConveyorBelt ;
689+ isDisturbTarget_ = conveyorBeltState.isDisturbTarget ;
690+
691+ if (ctrlModeConveyorBelt_ && modeConveyorBelt_ != conveyorBeltState.modeConveyorBelt ) {
692+ modeConveyorBelt_ = conveyorBeltState.modeConveyorBelt ;
693+ sendConveyorBeltMode ();
694+ }
695+ }
696+
697+ void sendConveyorBeltMode () {
698+ std_msgs::Int32 modeMessage;
699+ modeMessage.data = modeConveyorBelt_;
700+ pubConveyorBeltMode_.publish (modeMessage);
701+ }
702+
703+ void sendConveyorBeltSpeed (int cycleCount) {
704+ // Compute conveyor belt speed command
705+ float omegaPert = 2 .f * M_PI / 1 ;
706+ float deltaOmegaPert = 0 .1f * (2 .f * (float ) std::rand () / RAND_MAX - 1 .0f ) * omegaPert;
707+
708+ if (ctrlModeConveyorBelt_) {
709+ desSpeedConveyorBelt_ = (int ) (nominalSpeedConveyorBelt_
710+ + (int ) isDisturbTarget_ * magniturePertConveyorBelt_
711+ * sin ((omegaPert + deltaOmegaPert) * (1 / frequency_) * cycleCount));
712+
713+ // Send speed command to the conveyor belt
714+ std_msgs::Int32 speedMsgConveyorBelt;
715+ speedMsgConveyorBelt.data = desSpeedConveyorBelt_;
716+ if (ctrlModeConveyorBelt_ && (fmod (cycleCount, 30 ) == 0 )) { pubConveyorBeltSpeed_.publish (speedMsgConveyorBelt); }
717+ }
718+ }
642719};
0 commit comments