Skip to content

Instantly share code, notes, and snippets.

@AdoHaha
Created July 13, 2023 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdoHaha/6a9c0d6559d082b239b1256cbb845f3b to your computer and use it in GitHub Desktop.
Save AdoHaha/6a9c0d6559d082b239b1256cbb845f3b to your computer and use it in GitHub Desktop.
import com.kuka.roboticsAPI.geometricModel.Frame;
import com.kuka.roboticsAPI.geometricModel.Tool;
import com.kuka.roboticsAPI.geometricModel.math.CoordinateAxis;
import com.kuka.roboticsAPI.geometricModel.math.Transformation;
import com.kuka.roboticsAPI.motionModel.CartesianImpedanceControlMode;
// Assuming you've already set up the robot object
private LBR robot;
private Tool plastik1;
@Override
public void initialize() {
// Initialize the robot and tool
robot = getContext().getDeviceFromType(LBR.class);
plastik1 = getApplicationData().createFromTemplate("plastik1");
}
@Override
public void run() {
plastik1.attachTo(robot.getFlange());
while (true) {
// Get external wrench (force and torque) at the robot's flange
Wrench flangeWrench = robot.getExternalWrench();
// Get transformation between flange and tool
Frame flangeToTool = plastik1.getLoadData().getCenterOfMass().copyWithRedundancy();
// Transform the wrench to the tool frame
Wrench toolWrench = flangeWrench.changeSystem(flangeToTool);
// Get force and torque components
double[] toolForce = toolWrench.getForce().getArray();
double[] toolTorque = toolWrench.getTorque().getArray();
// Use or store these values as you like
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment