48
48
typedef Eigen::Matrix<float , 7 , 1 > Vector7f;
49
49
typedef Eigen::Matrix<float , 6 , 1 > Vector6f;
50
50
51
+ struct ConveyorBeltState {
52
+ bool ctrlModeConveyorBelt;
53
+ bool isDisturbTarget;
54
+ int modeConveyorBelt;
55
+ int nominalSpeedConveyorBelt;
56
+ int magniturePertConveyorBelt;
57
+ };
58
+
51
59
class RosDualArmCommunication {
52
60
private:
53
61
// ---- ROS
54
62
ros::NodeHandle nh_;// Ros node handle
55
63
ros::Rate loopRate_;// Ros loop rate [Hz]
64
+ double frequency_;
56
65
57
66
bool isSimulation_ = true ;
58
67
std::vector<float > objectDimVect_;
@@ -93,10 +102,19 @@ class RosDualArmCommunication {
93
102
// params update
94
103
std::string dsDampingTopicParams_[NB_ROBOTS];
95
104
105
+ // ---- Conveyor belt control
106
+ bool ctrlModeConveyorBelt_;
107
+ bool isDisturbTarget_;
108
+ int modeConveyorBelt_;
109
+ int nominalSpeedConveyorBelt_;
110
+ int magniturePertConveyorBelt_;
111
+ int desSpeedConveyorBelt_;
112
+
96
113
public:
97
114
// For controllers
98
115
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];
100
118
Eigen::Vector4f eeOrientation_[NB_ROBOTS], objectOrientation_, targetOrientation_, robotBaseOrientation_[NB_ROBOTS];
101
119
Vector7f jointPosition_[NB_ROBOTS], jointVelocity_[NB_ROBOTS], jointTorques_[NB_ROBOTS];
102
120
Eigen::Matrix<float , 6 , 1 > robotWrench_[NB_ROBOTS];
@@ -105,7 +123,7 @@ class RosDualArmCommunication {
105
123
// Robot ID: left or right
106
124
enum Robot { LEFT = 0 , RIGHT = 1 };
107
125
108
- RosDualArmCommunication (ros::NodeHandle& n, double frequency) : nh_(n), loopRate_(frequency){};
126
+ RosDualArmCommunication (ros::NodeHandle& n, double frequency) : nh_(n), loopRate_(frequency), frequency_(frequency) {};
109
127
110
128
~RosDualArmCommunication (){};
111
129
@@ -126,11 +144,9 @@ class RosDualArmCommunication {
126
144
initDampingTopicCtrl ();
127
145
initRosSubscribers ();
128
146
initRosPublisher ();
147
+ initConveyorBelt ();
129
148
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 ; }
134
150
135
151
if (nh_.ok ()) {
136
152
// Wait for poses being published
@@ -387,17 +403,6 @@ class RosDualArmCommunication {
387
403
pubDistAttractorEE_[LEFT] = nh_.advertise <std_msgs::Float64>(topicDistAttractorEE[LEFT], 1 );
388
404
pubDistAttractorEE_[RIGHT] = nh_.advertise <std_msgs::Float64>(topicDistAttractorEE[RIGHT], 1 );
389
405
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
-
401
406
return true ;
402
407
}
403
408
@@ -521,11 +526,6 @@ class RosDualArmCommunication {
521
526
msgFnormMoment.torque .z = -appliedWrench[k](5 );
522
527
pubAppliedFNormMoment_[k].publish (msgFnormMoment);
523
528
}
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); }
529
529
}
530
530
531
531
bool initDampingTopicCtrl () {
@@ -568,6 +568,36 @@ class RosDualArmCommunication {
568
568
return true ;
569
569
}
570
570
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
+
571
601
// ---- Callback functions
572
602
573
603
void objectPoseCallback (const geometry_msgs::Pose::ConstPtr& msg) {
@@ -639,4 +669,51 @@ class RosDualArmCommunication {
639
669
firstEigenPassiveDamping_[RIGHT] = paramValues[0 ];
640
670
if (firstEigenPassiveDamping_[RIGHT] < FLT_EPSILON) { firstEigenPassiveDamping_[RIGHT] = 150 .0f ; }
641
671
}
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
+ }
642
719
};
0 commit comments