Skip to content

Commit 0bd6357

Browse files
committed
keyboard disturbances + separate conveyor belt control + cycle count updated
1 parent 9c13d0d commit 0bd6357

File tree

5 files changed

+275
-207
lines changed

5 files changed

+275
-207
lines changed

dual_arm_control/include/dual_arm_control_iam/DualArmControlSim.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,20 @@ struct StateMachine {
8585
bool isThrowing;
8686
bool isPlacing;
8787
bool isPlaceTossing;
88-
bool isDisturbTarget;
8988
bool releaseAndretract;
9089
int dualTaskSelector;
9190
float desVtoss;
9291
float desiredVelImp;
9392
float placingPosHeight;
9493
float releasePosY;
9594

95+
//disturbance
96+
bool incrementReleasePos;
97+
Eigen::Vector3f deltaRelPos;
98+
Eigen::Vector3f deltaPos;
99+
float trackingFactor;
100+
bool adaptationActive;
101+
96102
bool startlogging;
97103
};
98104

@@ -127,7 +133,6 @@ struct tossingTaskVariables {
127133
class DualArmControlSim {
128134

129135
private:
130-
int cycleCount_;
131136
double periodT_;
132137

133138
// ---- Robot
@@ -140,9 +145,6 @@ class DualArmControlSim {
140145
bool objCtrlKey_;
141146
bool userSelect_ = true;
142147

143-
// ---- Target Disturbance
144-
bool isDisturbTarget_ = false;
145-
146148
// ====================================================================================================================
147149

148150
int contactState_; // Contact state with the object
@@ -224,10 +226,8 @@ class DualArmControlSim {
224226
float trackingFactor_;
225227

226228
bool incrementReleasePos_ = false;
227-
bool ctrlModeConveyorBelt_ = false;
228229
SphericalPosition releasePos_;
229230

230-
int desSpeedConveyorBelt_;
231231
Eigen::Vector2f dualPathLenAvgSpeed_;
232232
bool isIntercepting_ = false;
233233
float betaVelMod_;
@@ -338,9 +338,10 @@ class DualArmControlSim {
338338
Vector7f jointVelocity[],
339339
Vector7f jointTorques[],
340340
Eigen::Vector3f robotBasePos[],
341-
Eigen::Vector4f robotBaseOrientation[]);
341+
Eigen::Vector4f robotBaseOrientation[],
342+
int cycleCount);
342343
void updateContactState();
343-
void computeCommands(Eigen::Vector3f eePose[], Eigen::Vector4f eeOrientation[]);
344+
void computeCommands(Eigen::Vector3f eePose[], Eigen::Vector4f eeOrientation[], int cycleCount);
344345
void updatePoses();
345346

346347
void updateReleasePosition();

dual_arm_control/src/DualArmControlSim.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ void DualArmControlSim::reset() {
334334
bool DualArmControlSim::init() {
335335

336336
// TODO PUT IN YAML FILE?
337-
338-
cycleCount_ = 0;
339337
gravity_ << 0.0f, 0.0f, -9.80665f;
340338

341339
for (int k = 0; k < NB_ROBOTS; k++) {
@@ -405,7 +403,6 @@ bool DualArmControlSim::init() {
405403
//Keyboard interaction
406404
deltaRelPos_.setZero();
407405
deltaPos_.setZero();
408-
isDisturbTarget_ = false;
409406

410407
// TODO LOGGING OR NOT HERE?
411408
// startlogging_ = false;
@@ -546,7 +543,8 @@ CommandStruct DualArmControlSim::generateCommands(float firstEigenPassiveDamping
546543
Vector7f jointVelocity[],
547544
Vector7f jointTorques[],
548545
Eigen::Vector3f robotBasePos[],
549-
Eigen::Vector4f robotBaseOrientation[]) {
546+
Eigen::Vector4f robotBaseOrientation[],
547+
int cycleCount) {
550548

551549
d1_[LEFT] = firstEigenPassiveDamping[LEFT];
552550
d1_[RIGHT] = firstEigenPassiveDamping[RIGHT];
@@ -569,7 +567,7 @@ CommandStruct DualArmControlSim::generateCommands(float firstEigenPassiveDamping
569567
robotBaseOrientation);
570568

571569
updatePoses();
572-
computeCommands(eePose, eeOrientation);
570+
computeCommands(eePose, eeOrientation, cycleCount);
573571

574572
for (int k = 0; k < NB_ROBOTS; k++) {
575573
commandGenerated_.axisAngleDes[k] = robot_.getAxisAngleDes(k);
@@ -601,7 +599,7 @@ void DualArmControlSim::updateReleasePosition() {
601599
if (tossVar_.releasePosition(0) > 0.70) { tossVar_.releasePosition(0) = 0.70; }
602600
}
603601

604-
void DualArmControlSim::computeCommands(Eigen::Vector3f eePose[], Eigen::Vector4f eeOrientation[]) {
602+
void DualArmControlSim::computeCommands(Eigen::Vector3f eePose[], Eigen::Vector4f eeOrientation[], int cycleCount) {
605603
// Update contact state
606604
updateContactState();
607605

@@ -638,7 +636,7 @@ void DualArmControlSim::computeCommands(Eigen::Vector3f eePose[], Eigen::Vector4
638636
intercepLimits[3] = interceptMax(1);// y_max
639637

640638
// ---------- Application ----------
641-
if ((!releaseAndretract_) && (fmod(cycleCount_, 20) == 0)) {
639+
if ((!releaseAndretract_) && (fmod(cycleCount, 20) == 0)) {
642640
dualPathLenAvgSpeed_ = freeMotionCtrlEstim_.predictRobotTranslation(robot_.getWHEE(),
643641
object_.getWHGp(),
644642
robot_.getWHEEStandby(),
@@ -898,17 +896,6 @@ void DualArmControlSim::computeCommands(Eigen::Vector3f eePose[], Eigen::Vector4
898896

899897
// Extract linear velocity commands and desired axis angle command
900898
this->prepareCommands(robot_.getVelDesEE(), robot_.getQd(), object_.getVGpO());
901-
902-
// ---------- Control of conveyor belt speed ----------
903-
float omegaPert = 2.f * M_PI / 1;
904-
float deltaOmegaPert = 0.1f * (2.f * (float) std::rand() / RAND_MAX - 1.0f) * omegaPert;
905-
906-
// TODO
907-
// if (ctrlModeConveyorBelt_) {
908-
// desSpeedConveyorBelt_ = (int) (nominalSpeedConveyorBelt_
909-
// + (int) isDisturbTarget_ * magniturePertConveyorBelt_
910-
// * sin((omegaPert + deltaOmegaPert) * dt_ * cycleCount_));
911-
// }
912899
}
913900

914901
Eigen::Vector3f DualArmControlSim::computeInterceptWithTarget(const Eigen::Vector3f& xTarget,
@@ -1210,7 +1197,6 @@ StateMachine DualArmControlSim::getStateMachine() {
12101197
stateMachine.isThrowing = isThrowing_;
12111198
stateMachine.isPlacing = isPlacing_;
12121199
stateMachine.isPlaceTossing = isPlaceTossing_;
1213-
stateMachine.isDisturbTarget = isDisturbTarget_;
12141200
stateMachine.dualTaskSelector = dualTaskSelector_;
12151201
stateMachine.releaseAndretract = releaseAndretract_;
12161202
stateMachine.desVtoss = desVtoss_;
@@ -1219,6 +1205,12 @@ StateMachine DualArmControlSim::getStateMachine() {
12191205
stateMachine.releasePosY = tossVar_.releasePosition(1);
12201206
stateMachine.startlogging = startlogging_;
12211207

1208+
stateMachine.incrementReleasePos = incrementReleasePos_;
1209+
stateMachine.deltaRelPos = deltaRelPos_;
1210+
stateMachine.deltaPos = deltaPos_;
1211+
stateMachine.trackingFactor = trackingFactor_;
1212+
stateMachine.adaptationActive = adaptationActive_;
1213+
12221214
return stateMachine;
12231215
}
12241216

@@ -1229,13 +1221,17 @@ void DualArmControlSim::updateStateMachine(StateMachine stateMachine) {
12291221
isThrowing_ = stateMachine.isThrowing;
12301222
isPlacing_ = stateMachine.isPlacing;
12311223
isPlaceTossing_ = stateMachine.isPlaceTossing;
1232-
isDisturbTarget_ = stateMachine.isDisturbTarget;
12331224
dualTaskSelector_ = stateMachine.dualTaskSelector;
12341225
releaseAndretract_ = stateMachine.releaseAndretract;
12351226
desiredVelImp_ = stateMachine.desiredVelImp;
12361227
tossVar_.releasePosition(1) = stateMachine.releasePosY;
12371228
xPlacing_(2) = stateMachine.placingPosHeight;
12381229

1230+
deltaRelPos_ = stateMachine.deltaRelPos;
1231+
deltaPos_ = stateMachine.deltaPos;
1232+
trackingFactor_ = stateMachine.trackingFactor;
1233+
adaptationActive_ = stateMachine.adaptationActive;
1234+
12391235
if (desVtoss_ != stateMachine.desVtoss) {
12401236
desVtoss_ = stateMachine.desVtoss;
12411237
dsThrowing_.setTossLinearVelocity(desVtoss_ * tossVar_.releaseLinearVelocity.normalized());

ros_dual_arm/include/RosDualArmCommunication.hpp

Lines changed: 99 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,20 @@
4848
typedef Eigen::Matrix<float, 7, 1> Vector7f;
4949
typedef 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+
5159
class RosDualArmCommunication {
5260
private:
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+
96113
public:
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

Comments
 (0)