### Install Franky Python Module Source: https://github.com/timschneider42/franky/blob/master/README.md This command installs the Franky Python module using pip. Ensure the compiled library `_franky.cpython-3**-****-linux-gnu.so` is accessible in the Python path. ```bash pip install . ``` -------------------------------- ### Install Franky with Specific libfranka Version (Bash) Source: https://github.com/timschneider42/franky/blob/master/README.md This command sequence installs a specific version of the franky-control library along with its corresponding libfranka wheels. It involves downloading a zip file containing wheels for a specified libfranka version, unzipping it, and then installing numpy and franky-control using local wheels. ```bash VERSION=0-9-2 wget https://github.com/TimSchneider42/franky/releases/latest/download/libfranka_${VERSION}_wheels.zip unzip libfranka_${VERSION}_wheels.zip pip install numpy pip install --no-index --find-links=./dist franky-control ``` -------------------------------- ### Install CUDA on Real-time Kernel (Bash) Source: https://github.com/timschneider42/franky/blob/master/README.md This script installs CUDA on a real-time kernel. It downloads a bash script from GitHub, makes it executable, and then runs it. The script is designed to handle the complexities of installing CUDA on systems with a PREEMPT_RT kernel. ```bash # Download the script wget https://raw.githubusercontent.com/timschneider42/franky/master/tools/install_cuda_realtime.bash # Inspect the script to ensure it does what you expect # Make it executable chmod +x install_cuda_realtime.bash # Execute the script ./install_cuda_realtime.bash ``` ```bash bash <(wget -qO- https://raw.githubusercontent.com/timschneider42/franky/master/tools/install_cuda_realtime.bash) ``` -------------------------------- ### Install Franky Python Library Source: https://github.com/timschneider42/franky/blob/master/README.md Install the franky-control Python package using pip. This command is used for setting up the library in an environment where real-time kernel and permissions are already configured. ```bash pip install franky-control ``` -------------------------------- ### Initialize Franky Robot Control in Python Source: https://github.com/timschneider42/franky/blob/master/README.md Initialize the Robot object in Python, connecting to the Franka robot via its IP address. This snippet demonstrates basic setup and setting a relative dynamics factor for slower movements. ```python from franky import * robot = Robot("10.90.90.1") # Replace this with your robot's IP # Let's start slow (this lets the robot use a maximum of 5% of its velocity, acceleration, and jerk limits) robot.relative_dynamics_factor = 0.05 ``` -------------------------------- ### Build Franky Robot Library using CMake Source: https://github.com/timschneider42/franky/blob/master/README.md This snippet outlines the steps to clone the Franky repository, configure the build with CMake, and install the library. It assumes necessary dependencies are pre-installed. The output is the compiled Franky library. ```bash git clone --recurse-submodules git@github.com:timschneider42/franky.git cd franky mkdir -p build cd build cmake -DCMAKE_BUILD_TYPE=Release .. make make install ``` -------------------------------- ### Execute Asynchronous Robot Motions and Preempt Them Source: https://context7.com/timschneider42/franky/llms.txt Control robot motions asynchronously, allowing the main thread to continue execution. New motions can preempt existing ones, enabling real-time trajectory updates. This example shows starting a motion, pausing, and then starting a new preempting motion. ```python import time from franky import Robot, Affine, CartesianMotion, ReferenceType robot = Robot("172.16.0.2") robot.relative_dynamics_factor = 0.05 # Start asynchronous motion motion1 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative) robot.move(motion1, asynchronous=True) # Preempt with new motion after 500ms time.sleep(0.5) motion2 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative) robot.move(motion2, asynchronous=True) # Wait for motion to complete robot.join_motion() # Check if motion is complete without blocking if robot.poll_motion(): print("Motion completed") else: print("Motion still in progress") # Join with timeout (returns False if timeout expires) completed = robot.join_motion(timeout=5.0) # 5 second timeout ``` -------------------------------- ### Define Reaction Motion Source: https://github.com/timschneider42/franky/blob/master/README.md Defines the motion that will be executed when a reaction condition is met. This example specifies moving the robot up by 1cm relative to its current position. ```python # It is important that the reaction motion uses the same control mode as the original motion. # Hence, we cannot register a JointMotion as a reaction motion to a CartesianMotion. # Move up by 1cm reaction_motion = CartesianMotion(Affine([0.0, 0.0, -0.01]), ReferenceType.Relative) ``` -------------------------------- ### Joint Velocity Control in Python Source: https://context7.com/timschneider42/franky/llms.txt Control robot joint velocities for continuous movement. This example demonstrates setting target velocities, holding them for a duration, and executing multi-waypoint velocity commands. It requires the 'franky' library. ```python from franky import Robot, JointMotion, JointVelocityMotion, JointVelocityWaypointMotion, JointVelocityWaypoint, Duration robot = Robot("172.16.0.2") robot.recover_from_errors() robot.relative_dynamics_factor = 0.1 # Go to initial position robot.move(JointMotion([0.0, 0.0, 0.0, -2.2, 0.0, 2.2, 0.7])) # Reach target joint velocities and hold for 3 seconds velocity_motion = JointVelocityMotion( [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05], duration=Duration(3000) # milliseconds ) robot.move(velocity_motion) # Multi-waypoint velocity control: accelerate, reverse, stop velocity_waypoint_motion = JointVelocityWaypointMotion([ JointVelocityWaypoint( [0.1, 0.3, -0.1, 0.0, 0.1, -0.2, 0.4], hold_target_duration=Duration(1000) ), JointVelocityWaypoint( [-0.1, -0.3, 0.1, 0.0, -0.1, 0.2, -0.4], hold_target_duration=Duration(2000) ), JointVelocityWaypoint([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]), # Stop ]) robot.move(velocity_waypoint_motion) ``` -------------------------------- ### Define Reaction with Lambda Condition and Motion (C++) Source: https://github.com/timschneider42/franky/blob/master/README.md This C++ example defines a reaction that stops motion if the Z-force exceeds 10N. It also shows how to use a lambda function for a custom condition (e.g., checking for self-collision violations) and another lambda to define the reaction's motion. ```cpp auto motion = CartesianMotion( RobotPose(Affine({0.0, 0.0, 0.2}), 0.0), ReferenceType::Relative); // Stop motion if force is over 10N auto stop_motion = StopMotion() motion .addReaction( Reaction( Measure::ForceZ() > 10.0, // [N], stop_motion)) .addReaction( Reaction( Condition( [](const franka::RobotState& state, double rel_time, double abs_time) { // Lambda condition return state.current_errors.self_collision_avoidance_violation; }), [](const franka::RobotState& state, double rel_time, double abs_time) { // Lambda reaction motion generator // (we are just returning a stop motion, but there could be arbitrary // logic here for generating reaction motions) return StopMotion(); }) )); robot.move(motion) ``` -------------------------------- ### Define Real-Time Reactions to Robot Events Source: https://context7.com/timschneider42/franky/llms.txt Set up conditions and reactions to handle unexpected events during robot motion. Reactions are triggered when measured values exceed defined thresholds, allowing for dynamic response to the environment. This example demonstrates stopping motion upon detecting contact. ```python from franky import ( Robot, JointMotion, CartesianMotion, CartesianStopMotion, Affine, RobotPose, ReferenceType, Measure, Reaction, RobotState ) def reaction_callback(robot_state: RobotState, rel_time: float, abs_time: float): print(f"Reaction fired at time {rel_time}s, absolute time {abs_time}s") robot = Robot("172.16.0.2") robot.recover_from_errors() robot.relative_dynamics_factor = 0.1 # Go to initial position robot.move(JointMotion([0.0, 0.0, 0.0, -2.2, 0.0, 2.2, 0.7])) # Create motion with force-based reaction motion_down = CartesianMotion(RobotPose(Affine([0.0, 0.0, 0.5])), ReferenceType.Relative) # Stop when Z force exceeds 5N (detected contact) reaction = Reaction(Measure.FORCE_Z < -5.0, CartesianStopMotion()) reaction.register_callback(reaction_callback) motion_down.add_reaction(reaction) robot.move(motion_down) # Available measures: FORCE_X, FORCE_Y, FORCE_Z, REL_TIME, ABS_TIME # Arithmetic operations on measures normal_force = (Measure.FORCE_X ** 2 + Measure.FORCE_Y ** 2 + Measure.FORCE_Z ** 2) ** 0.5 time_condition = Measure.ABS_TIME > 10.0 # Logical operations on conditions abort_condition = (normal_force > 30.0) | time_condition ``` -------------------------------- ### Cartesian Position Control in Python Source: https://context7.com/timschneider42/franky/llms.txt Execute linear motions in Cartesian space using absolute or relative targets. This example shows absolute and relative Cartesian movements, including orientation control and multi-waypoint motions with elbow angle adjustments. It depends on 'franky' and 'scipy'. ```python import math from scipy.spatial.transform import Rotation from franky import ( Robot, Affine, CartesianMotion, CartesianWaypointMotion, CartesianWaypoint, RobotPose, ElbowState, ReferenceType, RelativeDynamicsFactor, CartesianState, Twist ) robot = Robot("172.16.0.2") robot.recover_from_errors() robot.relative_dynamics_factor = 0.1 # Absolute Cartesian motion with orientation quat = Rotation.from_euler("xyz", [0, 0, math.pi / 2]).as_quat() motion_abs = CartesianMotion(Affine([0.4, -0.2, 0.3], quat)) robot.move(motion_abs) # With explicit elbow angle motion_elbow = CartesianMotion( RobotPose(Affine([0.4, -0.2, 0.3], quat), elbow_state=ElbowState(0.3)) ) robot.move(motion_elbow) # Relative Cartesian motion (20cm forward in end-effector frame) motion_rel = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative) robot.move(motion_rel) # Move backwards using inverse transform robot.move(CartesianMotion(Affine([0.2, 0.0, 0.0]).inverse, ReferenceType.Relative)) # Multi-waypoint motion with dynamics scaling waypoint_motion = CartesianWaypointMotion([ CartesianWaypoint(RobotPose(Affine([0.0, 0.0, -0.12]), ElbowState(-0.2)), ReferenceType.Relative), CartesianWaypoint(Affine([0.08, 0.0, 0.0]), ReferenceType.Relative, RelativeDynamicsFactor(0.5, 1.0, 1.0)), CartesianWaypoint(Affine([0.0, 0.1, 0.0]), ReferenceType.Relative), ]) robot.move(waypoint_motion) # Waypoints with target velocities for smooth transitions smooth_motion = CartesianWaypointMotion([ CartesianWaypoint(Affine([0.5, -0.2, 0.3], quat)), CartesianWaypoint(CartesianState( pose=Affine([0.4, -0.1, 0.3], quat), velocity=Twist([-0.01, 0.01, 0.0]) )), CartesianWaypoint(Affine([0.3, 0.0, 0.3], quat)), ]) robot.move(smooth_motion) ``` -------------------------------- ### Cartesian Velocity Control in Python Source: https://context7.com/timschneider42/franky/llms.txt Control robot Cartesian velocities (twist), including linear and angular components. This example demonstrates setting target velocities for a duration, with explicit elbow velocity control, and multi-waypoint velocity commands. It requires the 'franky' library. ```python from franky import ( Robot, JointMotion, CartesianVelocityMotion, CartesianVelocityWaypointMotion, CartesianVelocityWaypoint, Twist, RobotVelocity, Duration ) robot = Robot("172.16.0.2") robot.recover_from_errors() robot.relative_dynamics_factor = 0.1 # Go to initial position robot.move(JointMotion([0.0, 0.0, 0.0, -2.2, 0.0, 2.2, 0.7])) # Cartesian velocity motion with linear and angular components velocity_motion = CartesianVelocityMotion( Twist(linear_velocity=[0.03, 0.03, 0.03], angular_velocity=[0.03, 0.03, 0.03]), duration=Duration(3000) ) robot.move(velocity_motion) # With explicit elbow velocity velocity_with_elbow = CartesianVelocityMotion( RobotVelocity(Twist([0.2, -0.1, 0.1], [0.1, -0.1, 0.2]), elbow_velocity=-0.2) ) robot.move(velocity_with_elbow) # Multi-waypoint velocity control velocity_waypoints = CartesianVelocityWaypointMotion([ CartesianVelocityWaypoint( Twist([0.2, -0.1, 0.1], [0.1, -0.1, 0.2]), hold_target_duration=Duration(1000) ), CartesianVelocityWaypoint( Twist([-0.2, 0.1, -0.1], [-0.1, 0.1, -0.2]), hold_target_duration=Duration(2000) ), CartesianVelocityWaypoint(Twist()), # Stop ]) robot.move(velocity_waypoints) ``` -------------------------------- ### Define Cartesian Motion for Reaction Source: https://github.com/timschneider42/franky/blob/master/README.md Defines a Cartesian motion that can be used as part of a real-time reaction. This example creates a motion to move the robot down by 10cm relative to its current position. ```python from franky import CartesianMotion, Affine, ReferenceType, Measure, Reaction motion = CartesianMotion(Affine([0.0, 0.0, 0.1]), ReferenceType.Relative) # Move down 10cm ``` -------------------------------- ### Define Cartesian Velocity Waypoint Motion Sequence Source: https://github.com/timschneider42/franky/blob/master/README.md Defines a sequence of Cartesian velocity waypoints, allowing the robot to accelerate to target velocities and hold them for specified durations. The example shows acceleration, holding, reversing, and stopping. ```python from franky import * # Cartesian velocity motions also support multiple waypoints. Unlike in Cartesian position # control, a Cartesian velocity waypoint is a target velocity to be reached. This particular # example first accelerates the end-effector, holds the velocity for 1s, then reverses # direction for 2s, reverses direction again for 1s, and finally stops. It is important not to ``` -------------------------------- ### Read Franka Robot State Information (Python) Source: https://context7.com/timschneider42/franky/llms.txt Accesses the current state of a Franka robot, including joint positions, velocities, end-effector pose, and full franka::RobotState data. It also provides methods to get Cartesian and joint states, and compute forward kinematics and Jacobians using the robot model. Dependencies include the 'franky' library. ```python from franky import Robot, Frame robot = Robot("172.16.0.2") # Get full robot state (extends franka::RobotState) state = robot.state print(f"Joint positions: {state.q}") print(f"Joint velocities: {state.dq}") print(f"End-effector transform: {state.O_T_EE}") print(f"Elbow position: {state.elbow}") # Get cartesian state cartesian_state = robot.current_cartesian_state robot_pose = cartesian_state.pose ee_pose = robot_pose.end_effector_pose elbow_pos = robot_pose.elbow_state robot_velocity = cartesian_state.velocity ee_twist = robot_velocity.end_effector_twist # Get joint state joint_state = robot.current_joint_state joint_pos = joint_state.position joint_vel = joint_state.velocity # Use robot model for forward kinematics q = [-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7] from franky import Affine f_t_ee = Affine() ee_t_k = Affine() ee_pose_computed = robot.model.pose(Frame.EndEffector, q, f_t_ee, ee_t_k) # Get Jacobian from current state jacobian = robot.model.body_jacobian(Frame.EndEffector, state) ``` -------------------------------- ### Control Franky Gripper Movement and Grasping (C++) Source: https://github.com/timschneider42/franky/blob/master/README.md Demonstrates how to initialize and control a Franky gripper in C++. It covers setting gripper speed and force, moving to specific widths, grasping objects, retrieving object width, releasing, and using asynchronous operations with timeouts. Requires the franky.hpp header. ```c++ #include #include #include auto gripper = franky::Gripper("10.90.90.1"); double speed = 0.02; // [m/s] double force = 20.0; // [N] // Move the fingers to a specific width (5cm) bool success = gripper.move(0.05, speed); // Grasp an object of unknown width success &= gripper.grasp(0.0, speed, force, epsilon_outer=1.0); // Get the width of the grasped object double width = gripper.width(); // Release the object gripper.open(speed); // There are also asynchronous versions of the methods std::future success_future = gripper.moveAsync(0.05, speed); // Wait for 1s if (!success_future.wait_for(std::chrono::seconds(1)) == std::future_status::ready) { // Get the result std::cout << "Success: " << success_future.get() << std::endl; } else { gripper.stop(); success_future.wait(); std::cout << "Gripper motion timed out." << std::endl; } ``` -------------------------------- ### Basic Robot Motion in C++ Source: https://github.com/timschneider42/franky/blob/master/README.md This C++ code snippet demonstrates connecting to a Franky robot, setting dynamic parameters, defining a relative Cartesian motion, and executing the move. It requires the `franky.hpp` header and the Franky library linked. ```cpp #include using namespace franky; // Connect to the robot with the FCI IP address Robot robot("10.90.90.1"); // Reduce velocity and acceleration of the robot robot.setRelativeDynamicsFactor(0.05); // Move the end-effector 20cm in positive x-direction auto motion = std::make_shared(RobotPose(Affine({0.2, 0.0, 0.0}), 0.0), ReferenceType::Relative); // Finally move the robot robot.move(motion); ``` -------------------------------- ### Combine Conditions with Logic Operators (Python) Source: https://github.com/timschneider42/franky/blob/master/README.md Demonstrates how to combine multiple boolean conditions using logical operators like negation (~), disjunction (|), and conjunction (&) to create more complex control logic for reactions or motion aborts. ```python abort = ~normal_force_within_bounds | time_up fast_abort = ~normal_force_within_bounds | time_up ``` -------------------------------- ### Control Franky Gripper Movement and Grasping (Python) Source: https://github.com/timschneider42/franky/blob/master/README.md Illustrates how to use the Franky gripper in Python, mirroring the C++ API. This includes initializing the gripper, setting speed and force, performing movements, grasping, checking width, releasing, and utilizing asynchronous methods with wait functionality. Requires the franky Python package. ```python import franky gripper = franky.Gripper("10.90.90.1") speed = 0.02 # [m/s] force = 20.0 # [N] # Move the fingers to a specific width (5cm) success = gripper.move(0.05, speed) # Grasp an object of unknown width success &= gripper.grasp(0.0, speed, force, epsilon_outer=1.0) # Get the width of the grasped object width = gripper.width # Release the object gripper.open(speed) # There are also asynchronous versions of the methods success_future = gripper.move_async(0.05, speed) # Wait for 1s if success_future.wait(1): print(f"Success: {success_future.get()}") else: gripper.stop() success_future.wait() print("Gripper motion timed out.") ``` -------------------------------- ### Build Franky and Wheels with Docker Source: https://github.com/timschneider42/franky/blob/master/README.md These Docker commands build the Franky environment, run tests, and create wheels for all supported Python versions. This is useful for creating distributable packages or ensuring compatibility across different Python environments. ```bash docker compose build franky-build docker compose run --rm franky-build run-tests docker compose run --rm franky-build build-wheels ``` -------------------------------- ### Automate Robot Control Workflow with RobotWebSession Source: https://github.com/timschneider42/franky/blob/master/README.md Demonstrates a typical automated workflow for controlling a Franka robot using the `RobotWebSession`. This includes taking control, unlocking brakes, enabling FCI, performing robot operations, and then disabling FCI and locking brakes. It handles potential `TakeControlTimeoutError` by attempting a forceful takeover. ```python import franky with franky.RobotWebSession("10.90.90.1", "username", "password") as robot_web_session: # First take control try: # Try taking control. The session currently holding control has to release it in order # for this session to gain control. In the web interface, a notification will show # prompting the user to release control. If the other session is another # franky.RobotWebSession, then the `release_control` method can be called on the other # session to release control. robot_web_session.take_control(wait_timeout=10.0) except franky.TakeControlTimeoutError: # If nothing happens for 10s, we try to take control forcefully. This is particularly # useful if the session holding control is dead. Taking control by force requires the # user to manually push the blue button close to the robot's wrist. robot_web_session.take_control(wait_timeout=30.0, force=True) # Unlock the brakes robot_web_session.unlock_brakes() # Enable the FCI robot_web_session.enable_fci() # Create a franky.Robot instance and do whatever you want ... # Disable the FCI robot_web_session.disable_fci() # Lock brakes robot_web_session.lock_brakes() ``` -------------------------------- ### Build Franky Docker Image (Bash) Source: https://github.com/timschneider42/franky/blob/master/README.md This command builds the franky-run Docker image. It clones the Franky repository recursively and then uses docker compose to build the image. A specific libfranka version can be specified using a build argument. ```bash git clone --recurse-submodules https://github.com/timschneider42/franky.git cd franky/ docker compose build franky-run ``` ```bash docker compose build franky-run --build-arg LIBFRANKA_VERSION=0.9.2 ``` -------------------------------- ### Robot Session Management and Control with RobotWebSession Source: https://context7.com/timschneider42/franky/llms.txt Manages robot login/logout, takes control, unlocks brakes, enables FCI, checks system status, executes self-tests, sets operating modes, and performs cleanup operations. Requires RobotWebSession, TakeControlTimeoutError. ```python from franky import RobotWebSession, TakeControlTimeoutError import time # Context manager handles login/logout automatically with RobotWebSession("172.16.0.2", "username", "password") as session: # Take control of the robot try: session.take_control(wait_timeout=10.0) except TakeControlTimeoutError: # Force control (requires pressing blue button) session.take_control(wait_timeout=30.0, force=True) # Unlock brakes and enable FCI session.unlock_brakes() session.enable_fci() # Check system status status = session.get_system_status() print(f"Time until self-test: {status['safety']['timeToTd2']}s") # Execute self-test if needed (every 24h) if status["safety"]["timeToTd2"] < 300: # Less than 5 minutes session.disable_fci() session.lock_brakes() time.sleep(1.0) session.execute_self_test() session.unlock_brakes() session.enable_fci() # Set operating mode session.set_mode_programming() # For teaching session.set_mode_execution() # For running programs # Cleanup session.disable_fci() session.lock_brakes() session.release_control() ``` -------------------------------- ### Robot Dynamics Control in Python Source: https://github.com/timschneider42/franky/blob/master/README.md This Python code illustrates how to control the dynamic limits (velocity, acceleration, jerk) of a Franky robot. It shows methods for recovering from errors, setting a uniform relative dynamics factor, and defining individual constraints. ```python from franky import * robot = Robot("10.90.90.1") # Recover from errors robot.recover_from_errors() # Set velocity, acceleration, and jerk to 5% of the maximum robot.relative_dynamics_factor = 0.05 # Alternatively, you can define each constraint individually robot.relative_dynamics_factor = RelativeDynamicsFactor( velocity=0.1, acceleration=0.05, jerk=0.1 ) ``` -------------------------------- ### Basic Robot Motion in Python Source: https://github.com/timschneider42/franky/blob/master/README.md This Python code snippet shows how to connect to a Franky robot, adjust its dynamics, define a relative Cartesian motion, and command the robot to move. It uses the `franky` module and assumes the robot's IP address is accessible. ```python from franky import Affine, CartesianMotion, Robot, ReferenceType robot = Robot("10.90.90.1") robot.relative_dynamics_factor = 0.05 motion = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative) robot.move(motion) ``` -------------------------------- ### Register Callbacks for Robot Motion Monitoring Source: https://context7.com/timschneider42/franky/llms.txt Monitor robot motion execution at a high frequency (1kHz) by registering callbacks. This is useful for logging, debugging, and performance profiling. The callback function receives detailed state information at each time step. ```python from franky import ( Robot, JointMotion, RobotState, Duration, JointPositions ) robot = Robot("172.16.0.2") robot.relative_dynamics_factor = 0.1 def motion_callback( robot_state: RobotState, time_step: Duration, rel_time: Duration, abs_time: Duration, control_signal: JointPositions ): print(f"Time: {abs_time}, Target joints: {control_signal.q}") print(f"Current joints: {robot_state.q}") motion = JointMotion([0.0, 0.0, 0.0, -2.2, 0.0, 2.2, 0.7]) motion.register_callback(motion_callback) robot.move(motion) ``` -------------------------------- ### Connect and Configure Franka Robot Dynamics (Python) Source: https://context7.com/timschneider42/franky/llms.txt Connects to a Franka robot and configures its dynamics parameters using the Robot class. It allows setting global dynamics factors or individual velocity, acceleration, and jerk limits for translation, rotation, and joints. Dependencies include the 'franky' library. ```python from franky import Robot, RelativeDynamicsFactor # Connect to the robot using its FCI IP address robot = Robot("172.16.0.2") # Recover from any existing errors robot.recover_from_errors() # Set global dynamics factor (5% of max velocity, acceleration, jerk) robot.relative_dynamics_factor = 0.05 # Or set each component individually robot.relative_dynamics_factor = RelativeDynamicsFactor( velocity=0.1, acceleration=0.05, jerk=0.1 ) # Fine-grained dynamics control robot.translation_velocity_limit.set(3.0) # [m/s] robot.rotation_velocity_limit.set(2.5) # [rad/s] robot.elbow_velocity_limit.set(2.62) # [rad/s] robot.translation_acceleration_limit.set(9.0) # [m/s^2] robot.rotation_acceleration_limit.set(17.0) # [rad/s^2] robot.translation_jerk_limit.set(4500.0) # [m/s^3] robot.joint_velocity_limit.set([2.62, 2.62, 2.62, 2.62, 5.26, 4.18, 5.26]) robot.joint_acceleration_limit.set([10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]) robot.joint_jerk_limit.set([5000.0, 5000.0, 5000.0, 5000.0, 5000.0, 5000.0, 5000.0]) # Check max limits print(f"Max joint jerk: {robot.joint_jerk_limit.max}") ``` -------------------------------- ### Control Franka Gripper for Grasping Operations Source: https://context7.com/timschneider42/franky/llms.txt Manage the Franka gripper for various grasping tasks. Supports both synchronous and asynchronous control for moving to specific widths, grasping with force control, and releasing objects. Includes methods for checking gripper state and homing. ```python from franky import Gripper gripper = Gripper("172.16.0.2") speed = 0.02 # [m/s] force = 20.0 # [N] # Move fingers to specific width success = gripper.move(0.05, speed) # Grasp object with force control success = gripper.grasp(0.0, speed, force, epsilon_outer=1.0) # Get gripper state width = gripper.width is_grasped = gripper.is_grasped max_width = gripper.max_width # Release object gripper.open(speed) # Asynchronous gripper control future = gripper.move_async(0.05, speed) if future.wait(1.0): # Wait up to 1 second print(f"Move success: {future.get()}") else: gripper.stop() future.wait() print("Gripper motion timed out") # Homing (calibration) gripper.homing() ``` -------------------------------- ### Execute Asynchronous Motion (Python) Source: https://github.com/timschneider42/franky/blob/master/README.md This Python code demonstrates how to execute a robot motion asynchronously by setting the `asynchronous` parameter to `True` in the `robot.move` call. This allows the main thread to continue execution without waiting for the motion to complete. ```python import time from franky import Affine, CartesianMotion, Robot, ReferenceType robot = Robot("10.90.90.1") robot.relative_dynamics_factor = 0.05 motion1 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative) robot.move(motion1, asynchronous=True) time.sleep(0.5) # Note that, similar to reactions, when preempting active motions with new motions, the # control mode cannot change. Hence, we cannot use, e.g., a JointMotion here. motion2 = CartesianMotion(Affine([0.2, 0.0, 0.0]), ReferenceType.Relative) robot.move(motion2, asynchronous=True) ``` -------------------------------- ### Access Robot Web Session API for Control and Diagnostics Source: https://context7.com/timschneider42/franky/llms.txt Programmatically interact with the Franka robot's web interface. This API allows for control over brake engagement, FCI enabling, and execution of self-tests, facilitating automated workflows and remote management. ```python import time from franky import RobotWebSession, TakeControlTimeoutError ``` -------------------------------- ### Register Reaction Callback (Python) Source: https://github.com/timschneider42/franky/blob/master/README.md This snippet illustrates how to register a callback function that will be executed when a specific reaction is triggered. The callback receives the robot's state and timing information, allowing for custom actions upon reaction. ```python from franky import RobotState def reaction_callback(robot_state: RobotState, rel_time: float, abs_time: float): print(f"Reaction fired at {abs_time}.") reaction.register_callback(reaction_callback) ``` -------------------------------- ### Define Boolean Conditions (Python) Source: https://github.com/timschneider42/franky/blob/master/README.md Shows how to create boolean conditions based on calculated normal force and elapsed time. These conditions can then be used to control robot behavior, such as initiating an abort sequence. ```python normal_force_within_bounds = normal_force < 30.0 time_up = Measure.ABS_TIME > 10.0 ``` -------------------------------- ### Affine Transformations for Poses and Transformations Source: https://context7.com/timschneider42/franky/llms.txt Performs geometric calculations using the Affine class, a wrapper around Eigen::Affine3d. Supports translation, rotation (from quaternion), composition, and inversion of transformations. Units are meters for distance and radians for rotation. ```python import math from scipy.spatial.transform import Rotation from franky import Affine # Create translation z_translation = Affine([0.0, 0.0, 0.5]) # Create rotation from quaternion quat = Rotation.from_euler("xyz", [0, 0, math.pi / 2]).as_quat() z_rotation = Affine([0.0, 0.0, 0.0], quat) # Compose transformations combined = z_translation * z_rotation # Get inverse transformation inverse = combined.inverse # Units: distances in meters [m], rotations in radians [rad] ``` -------------------------------- ### Register Callback for Motion Source: https://github.com/timschneider42/franky/blob/master/README.md Registers a callback function to be invoked at each control step (1kHz) during a robot motion. The callback receives robot state information and control signals. ```python def cb( robot_state: RobotState, time_step: Duration, rel_time: Duration, abs_time: Duration, control_signal: JointPositions, ): print(f"At time {abs_time}, the target joint positions were {control_signal.q}") m_jp1.register_callback(cb) robot.move(m_jp1) ``` -------------------------------- ### Automate Franka Robot Safety Self-Test Source: https://github.com/timschneider42/franky/blob/master/README.md Shows how to automate the Franka robot's safety self-test using `RobotWebSession`. The code checks the system status to see if the self-test is due within 5 minutes and, if so, disables the FCI, locks the brakes, executes the self-test, and then re-enables the FCI and unlocks the brakes. ```python import time import franky with franky.RobotWebSession("10.90.90.1", "username", "password") as robot_web_session: # Execute self-test if the time until self-test is less than 5 minutes. if robot_web_session.get_system_status()["safety"]["timeToTd2"] < 300: robot_web_session.disable_fci() robot_web_session.lock_brakes() time.sleep(1.0) robot_web_session.execute_self_test() robot_web_session.unlock_brakes() robot_web_session.enable_fci() time.sleep(1.0) # Recreate your franky.Robot instance as the FCI has been disabled and re-enabled ... ``` -------------------------------- ### Geometric Transformations with Franky Affine in Python Source: https://github.com/timschneider42/franky/blob/master/README.md This Python snippet demonstrates creating and combining geometric transformations using `franky.Affine`, which wraps Eigen::Affine3d. It shows how to create translations and rotations, and then combine them for complex transformations. Distances are in meters and rotations in radians. ```python import math from scipy.spatial.transform import Rotation from franky import Affine z_translation = Affine([0.0, 0.0, 0.5]) quat = Rotation.from_euler("xyz", [0, 0, math.pi / 2]).as_quat() z_rotation = Affine([0.0, 0.0, 0.0], quat) combined_transformation = z_translation * z_rotation ``` -------------------------------- ### Trigger Reaction on Force Threshold (Python) Source: https://github.com/timschneider42/franky/blob/master/README.md This snippet demonstrates how to define a reaction that triggers when the Z-force exceeds a specified threshold. It involves creating a Reaction object with a force condition and an associated motion, then adding this reaction to a motion object before executing the motion. ```python reaction = Reaction(Measure.FORCE_Z > 5.0, reaction_motion) motion.add_reaction(reaction) robot.move(motion) ``` -------------------------------- ### Synchronize with Asynchronous Motion (Python) Source: https://github.com/timschneider42/franky/blob/master/README.md This snippet shows how to synchronize the main thread with an ongoing asynchronous motion using `robot.join_motion()`. This method will block until the robot has finished its current motion, ensuring that subsequent operations occur only after the motion is complete. ```python robot.join_motion() ``` -------------------------------- ### Move Robot with Dynamics Factor in Move Command Source: https://github.com/timschneider42/franky/blob/master/README.md Executes a robot motion (`m_jp2`) while applying a specific relative dynamics factor within the `move` command. This factor is multiplied with any globally set dynamics factors. ```python robot.move(m_jp2, relative_dynamics_factor=0.8) ``` -------------------------------- ### Set Franka Robot Velocity and Acceleration Limits Source: https://github.com/timschneider42/franky/blob/master/README.md Configures individual and joint-specific velocity, acceleration, and jerk limits for the Franka robot. These settings allow for fine-grained control over the robot's motion dynamics. The limits can be set to specific values or retrieved using the .max property. ```python robot.translation_velocity_limit.set(3.0) robot.rotation_velocity_limit.set(2.5) robot.elbow_velocity_limit.set(2.62) robot.translation_acceleration_limit.set(9.0) robot.rotation_acceleration_limit.set(17.0) robot.elbow_acceleration_limit.set(10.0) robot.translation_jerk_limit.set(4500.0) robot.rotation_jerk_limit.set(8500.0) robot.elbow_jerk_limit.set(5000.0) robot.joint_velocity_limit.set([2.62, 2.62, 2.62, 2.62, 5.26, 4.18, 5.26]) robot.joint_acceleration_limit.set([10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]) robot.joint_jerk_limit.set([5000.0, 5000.0, 5000.0, 5000.0, 5000.0, 5000.0, 5000.0]) print(robot.joint_jerk_limit.max) ``` -------------------------------- ### Franka Robot Kinematics and Model Access Source: https://github.com/timschneider42/franky/blob/master/README.md Performs forward kinematics calculations using the robot's model to determine end-effector pose and computes the body Jacobian for the current robot state. It also allows access to the robot's URDF model as a string for custom kinematic computations. Requires libfranka version 0.15.0 or higher for URDF access. ```python from franky import * robot = Robot("10.90.90.1") state = robot.state # Use the robot model to compute kinematics q = [-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7] f_t_ee = Affine() ee_t_k = Affine() ee_pose_kin = robot.model.pose(Frame.EndEffector, q, f_t_ee, ee_t_k) # Get the Jacobian of the current robot state jacobian = robot.model.body_jacobian(Frame.EndEffector, state) # Alternatively, just get the URDF as a string urdf_model = robot.model_urdf ``` -------------------------------- ### Calculate Normal Force (Python) Source: https://github.com/timschneider42/franky/blob/master/README.md Calculates the normal force acting on the robot by combining the forces in the X, Y, and Z directions using the Pythagorean theorem. This is useful for understanding the overall force experienced by the robot. ```python normal_force = (Measure.FORCE_X ** 2 + Measure.FORCE_Y ** 2 + Measure.FORCE_Z ** 2) ** 0.5 ``` -------------------------------- ### Define Cartesian Position Motion Source: https://github.com/timschneider42/franky/blob/master/README.md Moves the robot's end-effector to a specified target pose (position and orientation) in Cartesian space. Requires franky, scipy, and math libraries. ```python import math from scipy.spatial.transform import Rotation from franky import * # Move to the given target pose quat = Rotation.from_euler("xyz", [0, 0, math.pi / 2]).as_quat() m_cp1 = CartesianMotion(Affine([0.4, -0.2, 0.3], quat)) ``` -------------------------------- ### Define Cartesian Waypoint Motion with Velocities Source: https://github.com/timschneider42/franky/blob/master/README.md Defines a sequence of Cartesian waypoints, specifying target poses and velocities. This allows for continuous motion between waypoints rather than stopping at each one. ```python import math from scipy.spatial.transform import Rotation from franky import * # Cartesian waypoints permit specifying target velocities m_cp5 = CartesianWaypointMotion( [ CartesianWaypoint(Affine([0.5, -0.2, 0.3], quat)), CartesianWaypoint( CartesianState( pose=Affine([0.4, -0.1, 0.3], quat), velocity=Twist([-0.01, 0.01, 0.0]) ) ), CartesianWaypoint(Affine([0.3, 0.0, 0.3], quat)), ] ) ``` -------------------------------- ### Franka Joint Position Control Motion Source: https://github.com/timschneider42/franky/blob/master/README.md Defines point-to-point and waypoint-based motions in the robot's joint space. This allows for precise control of individual joint movements. Waypoint motions can include intermediate targets with specified velocities for continuous movement. ```python from franky import * # A point-to-point motion in the joint space m_jp1 = JointMotion([-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7]) # A motion in joint space with multiple waypoints. m_jp2 = JointWaypointMotion( [ JointWaypoint([-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7]), JointWaypoint([0.0, 0.3, 0.3, -1.5, -0.2, 1.5, 0.8]), JointWaypoint([0.1, 0.4, 0.3, -1.4, -0.3, 1.7, 0.9]), ] ) # Intermediate waypoints also permit specifying target velocities. ``` -------------------------------- ### Execute Joint Position Control Motions (Python) Source: https://context7.com/timschneider42/franky/llms.txt Executes point-to-point and waypoint-based motions in joint space using the Franky library. JointMotion moves to a single target, while JointWaypointMotion supports multiple waypoints with optional intermediate velocities for continuous motion. Dependencies include the 'franky' library. ```python from franky import Robot, JointMotion, JointWaypointMotion, JointWaypoint, JointState robot = Robot("172.16.0.2") robot.recover_from_errors() robot.relative_dynamics_factor = 0.1 # Point-to-point motion to a joint configuration motion = JointMotion([-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7]) robot.move(motion) # Waypoint motion (robot stops at each waypoint) waypoint_motion = JointWaypointMotion([ JointWaypoint([-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7]), JointWaypoint([0.0, 0.3, 0.3, -1.5, -0.2, 1.5, 0.8]), JointWaypoint([0.1, 0.4, 0.3, -1.4, -0.3, 1.7, 0.9]), ]) robot.move(waypoint_motion) # Waypoint motion with intermediate velocities (continuous motion) smooth_motion = JointWaypointMotion([ JointWaypoint([-0.3, 0.1, 0.3, -1.4, 0.1, 1.8, 0.7]), JointWaypoint(JointState( position=[0.0, 0.3, 0.3, -1.5, -0.2, 1.5, 0.8], velocity=[0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] # Non-zero velocity for smooth transition )), JointWaypoint([0.1, 0.4, 0.3, -1.4, -0.3, 1.7, 0.9]), ]) robot.move(smooth_motion) ``` -------------------------------- ### Retrieve Franka Robot State Information Source: https://github.com/timschneider42/franky/blob/master/README.md Accesses and extracts detailed state information from the Franka robot, including its current joint positions, velocities, and Cartesian pose (end-effector and elbow). This data is crucial for monitoring and control feedback. The library provides specific objects for robot state, Cartesian state, and joint state. ```python from franky import * robot = Robot("10.90.90.1") # Get the current state as `franky.RobotState`. state = robot.state # Get the robot's cartesian state cartesian_state = robot.current_cartesian_state robot_pose = cartesian_state.pose ee_pose = robot_pose.end_effector_pose elbow_pos = robot_pose.elbow_state robot_velocity = cartesian_state.velocity ee_twist = robot_velocity.end_effector_twist elbow_vel = robot_velocity.elbow_velocity # Get the robot's joint state joint_state = robot.current_joint_state joint_pos = joint_state.position joint_vel = joint_state.velocity ```