libfranka 0.15.0
FCI C++ API
Loading...
Searching...
No Matches
vacuum_object.cpp

An example showing how to control FRANKA's vacuum gripper.

An example showing how to control FRANKA's vacuum gripper.

// Copyright (c) 2019 Franka Robotics GmbH
// Use of this source code is governed by the Apache-2.0 license, see LICENSE
#include <iostream>
#include <thread>
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "Usage: ./vacuum_object <vacuum-gripper-hostname>" << std::endl;
return -1;
}
franka::VacuumGripper vacuum_gripper(argv[1]);
try {
// Print a vacuum gripper state.
franka::VacuumGripperState vacuum_gripper_state = vacuum_gripper.readOnce();
std::cout << "Initial vacuum gripper state: " << vacuum_gripper_state << std::endl;
// Vacuum the object.
if (!vacuum_gripper.vacuum(100, std::chrono::milliseconds(1000))) {
std::cout << "Failed to vacuum the object." << std::endl;
return -1;
}
vacuum_gripper_state = vacuum_gripper.readOnce();
std::cout << "Vacuum gripper state after applying vacuum: " << vacuum_gripper_state
<< std::endl;
// Wait 3s and check afterwards, if the object is still grasped.
std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(3000));
vacuum_gripper_state = vacuum_gripper.readOnce();
if (!vacuum_gripper_state.in_control_range) {
std::cout << "Object lost." << std::endl;
return -1;
}
std::cout << "Vacuumed object, will release it now." << std::endl;
vacuum_gripper.dropOff(std::chrono::milliseconds(1000));
} catch (franka::Exception const& e) {
vacuum_gripper.stop();
std::cout << e.what() << std::endl;
return -1;
}
return 0;
}
Maintains a network connection to the vacuum gripper, provides the current vacuum gripper state,...
Definition vacuum_gripper.h:28
bool dropOff(std::chrono::milliseconds timeout) const
Drops the grasped object off.
bool stop() const
Stops a currently running vacuum gripper vacuum or drop off operation.
bool vacuum(uint8_t vacuum, std::chrono::milliseconds timeout, ProductionSetupProfile profile=ProductionSetupProfile::kP0) const
Vacuums an object.
VacuumGripperState readOnce() const
Waits for a vacuum gripper state update and returns it.
Contains exception definitions.
Base class for all exceptions used by libfranka.
Definition exception.h:20
Describes the vacuum gripper state.
Definition vacuum_gripper_state.h:31
bool in_control_range
Vacuum value within in setpoint area.
Definition vacuum_gripper_state.h:35
Contains the franka::VacuumGripper type.