赞
踩
深度解析Franka机器人的运动生成与控制——libfranka - 古月居
注意:Franka机器人的控制频率为1kHz,但是实际留给用户代码的执行时间只有300us,所以不能让代码冗长,也不要有太多额外的外部读写操作。
例子:
- double time = 0.0;
- auto control_callback = [&time](const franka::RobotState& robot_state,
- franka::Duration time_step) -> franka::JointPositions {
- time += time_step.toSec(); // Update time at the beginning of the callback.
- franka::JointPositions output = getJointPositions(time);
- if (time >= max_time) {
- // Return MotionFinished at the end of the trajectory.
- return franka::MotionFinished(output);
- }
- return output;
- }
关节位置运动生成示例:
- #include <cmath>
- #include <iostream>
- #include <franka/exception.h>
- #include <franka/robot.h>
-
- int main(int argc, char** argv) {
- if (argc != 2) {
- std::cerr << "Usage: " << argv[0] << "IP-Address" << std::endl;
- return -1;
- }
- try
- {
- franka::Robot robot(argv[1]);
- robot.setCollisionBehavior(
- {{20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0}}, {{20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0}},
- {{10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0}}, {{10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0}},
- {{20.0, 20.0, 20.0, 20.0, 20.0, 20.0}}, {{20.0, 20.0, 20.0, 20.0, 20.0, 20.0}},
- {{10.0, 10.0, 10.0, 10.0, 10.0, 10.0}}, {{10.0, 10.0, 10.0, 10.0, 10.0, 10.0}});
- robot.setJointImpedance({{3000, 3000, 3000, 2500, 2500, 2000, 2000}});
- robot.setCartesianImpedance({{3000, 3000, 3000, 300, 300, 300}});
- std::cout << "Please make sure to have the user stop button at hand!" << std::endl
- << "Press Enter to continue..." << std::endl;
- std::cin.ignore();
- std::array<double, 7> initial_position;
- double time = 0.0;
- robot.control([&initial_position, &time](const franka::RobotState& robot_state,
- franka::Duration period) -> franka::JointPositions {
- time += period.toSec();
- if (time == 0.0) {
- initial_position = robot_state.q_d;
- }
- double delta_angle = M_PI / 8.0 * (1 - std::cos(M_PI / 2.5 * time));
- franka::JointPositions output = {{initial_position[0], initial_position[1],
- initial_position[2], initial_position[3],
- initial_position[4], initial_position[5],
- initial_position[6] + delta_angle}};
- if (time >= 5) {
- std::cout << std::endl << "Finished motion, shutting down robot" << std::endl;
- return franka::MotionFinished(output);
- }
- return output;
- });
- }
- catch(const franka::Exception& e)
- {
- std::cerr << e.what() << std::endl;
- return -1;
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。