set_desired_force
This function defines the target force and torque for each task-space axis, along with the direction mask,
transition time, and control mode. It linearly transitions from the current force to the target values over fTargetTime.
Definition
DRFLEx.h within class CDRFLEx, public section
bool set_desired_force(float fTargetForce[NUM_TASK],
unsigned char iTargetDirection[NUM_TASK],
COORDINATE_SYSTEM eForceReference = COORDINATE_SYSTEM_TOOL,
float fTargetTime = 0.f,
FORCE_MODE eForceMode = FORCE_MODE_ABSOLUTE) {
return _set_desired_force(_rbtCtrl, fTargetForce, iTargetDirection, eForceReference, fTargetTime, eForceMode);
};
Parameter
Parameter Name |
Data Type |
Default Value |
Description |
|---|---|---|---|
fTargetForce |
float[6] |
Target forces and torques applied along the task-space axes: [Fx, Fy, Fz, Mx, My, Mz]. |
|
iTargetDirection |
unsigned char[6] |
Axis mask for control |
|
eForceReference |
|
Coordinate system where the force is defined (e.g., TOOL, BASE, WORLD). |
|
fTargetTime |
float |
0 |
Transition time [sec] for the force ramp (0–1.0). |
eForceMode |
|
Force mode (absolute for direct control, relative for incremental application). |
Return
Value |
Description |
|---|---|
0 |
Failed |
1 |
Success |
Note
When the address passed to open_connection is exactly “127.0.0.1”, task_compliance_ctrl, set_stiffnessx, release_compliance_ctrl, set_desired_force and release_force return true without sending the command to the controller.
Example A — Manual Mode (Pressing During Teaching)
// Preconditions: Connected, Teach mode active, Servo ON.
// 1) Enable compliance with moderate stiffness
float stiff[6] = {3000.f, 3000.f, 3000.f, 200.f, 200.f, 200.f};
drfl.task_compliance_ctrl(stiff, COORDINATE_SYSTEM_TOOL, 0.0f);
// 2) Apply +20 N along TOOL Z axis
float fTarget[6] = {0.f, 0.f, 20.f, 0.f, 0.f, 0.f};
unsigned char dir[6] = {0, 0, 1, 0, 0, 0}; // control only Z
drfl.set_desired_force(fTarget, dir, COORDINATE_SYSTEM_TOOL, 0.3f, FORCE_MODE_ABSOLUTE);
printf("Force control active: +20N along TOOL Z.\n");
// 3) Gradually release the applied force
drfl.release_force(0.4f);
drfl.release_compliance_ctrl();
Example B — Auto Mode (Force-Controlled Insertion Task)
// Preconditions: Robot connected, Auto mode active, motion sequence running.
// 1) Move to approach position
float p_app[NUM_TASK] = {550.f, 200.f, 130.f, 180.f, 0.f, 0.f};
float vel1[2] = {100.f, 30.f}, acc1[2] = {400.f, 150.f};
drfl.movel(p_app, vel1, acc1);
drfl.mwait();
// 2) Enable compliance
float stiff[6] = {2500.f, 2500.f, 1500.f, 150.f, 150.f, 150.f};
drfl.task_compliance_ctrl(stiff, COORDINATE_SYSTEM_TOOL, 0.1f);
// 3) Apply downward insertion force (+Z)
float fTarget[6] = {0.f, 0.f, 30.f, 0.f, 0.f, 0.f};
unsigned char dir[6] = {0, 0, 1, 0, 0, 0};
drfl.set_desired_force(fTarget, dir, COORDINATE_SYSTEM_TOOL, 0.2f, FORCE_MODE_ABSOLUTE);
// 4) Perform insertion motion
float p_down[NUM_TASK] = {550.f, 200.f, 90.f, 180.f, 0.f, 0.f};
float vel2[2] = {50.f, 20.f}, acc2[2] = {200.f, 80.f};
drfl.movel(p_down, vel2, acc2);
drfl.mwait();
// 5) Release force and compliance
drfl.release_force(0.3f);
drfl.release_compliance_ctrl();
printf("Force-controlled insertion completed.\n");
Notes & Best Practices
If the robot enters EMERGENCY_STOP, SAFE_OFF or SAFE_OFF2 while the force is active, the force is released (except when connected with the address “127.0.0.1”, see open_connection).
Apply task_compliance_ctrl before setting a target force to ensure stable behavior.
Use the direction mask to apply force only along the required axes (e.g., pressing in Z while maintaining free X/Y).
Set a small
fTargetTime(0.2–0.5s) for smooth transitions and to avoid sudden motion.FORCE_MODE_RELATIVEcan be used to incrementally adjust existing force values during process adaptation.Always call release_force and release_compliance_ctrl after force-based tasks to restore normal control.