当前位置:   article > 正文

Franka机械臂代码学习——generate_joint_position_motion.cpp例程_position joint interface

position joint interface

该例程是给出机械臂的七个关节角,控制机械臂的运动。

  1. #include <cmath>
  2. // 是C++语言中标准库头文件
  3. #include <iostream>
  4. #include <franka/exception.h>
  5. #include <franka/robot.h>
  6. #include "examples_common.h"
  7. /**
  8. * @example generate_joint_position_motion.cpp
  9. * An example showing how to generate a joint position motion.
  10. *
  11. * @warning 注意!!!在运行本例程之前确保机械臂前方有足够的空间
  12. */
  13. int main(int argc, char** argv) {
  14. if (argc != 2) {
  15. std::cerr << "Usage: " << argv[0] << " <robot-hostname>" << std::endl;
  16. return -1;
  17. }
  18. try {
  19. franka::Robot robot(argv[1]);
  20. setDefaultBehavior(robot); // 设置默认碰撞行为、关节阻抗、笛卡尔阻抗和滤波器频率
  21. // 首先让机械臂运动到一个合适的关节空间
  22. std::array<double, 7> q_goal = {{0, -M_PI_4, 0, -3 * M_PI_4, 0, M_PI_2, M_PI_4}};
  23. MotionGenerator motion_generator(0.5, q_goal);
  24. // MotionGenerator (double speed_factor, const std::array< double, 7 > q_goal)
  25. std::cout << "WARNING: This example will move the robot! "
  26. << "Please make sure to have the user stop button at hand!" << std::endl
  27. << "Press Enter to continue..." << std::endl;
  28. std::cin.ignore();
  29. robot.control(motion_generator);
  30. std::cout << "Finished moving to initial joint configuration." << std::endl;
  31. // 始终在控制回路之前设置附加参数,不要在控制回路中!!!
  32. // 设置碰撞行为
  33. robot.setCollisionBehavior(
  34. {{20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0}}, {{20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0}},
  35. {{20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0}}, {{20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0}},
  36. {{20.0, 20.0, 20.0, 25.0, 25.0, 25.0}}, {{20.0, 20.0, 20.0, 25.0, 25.0, 25.0}},
  37. {{20.0, 20.0, 20.0, 25.0, 25.0, 25.0}}, {{20.0, 20.0, 20.0, 25.0, 25.0, 25.0}});
  38. // 设置转矩和力的阈值,大于这个阈值说明碰撞了
  39. std::array<double, 7> initial_position;
  40. double time = 0.0;
  41. robot.control([&initial_position, &time](const franka::RobotState& robot_state,
  42. franka::Duration period) -> franka::JointPositions {
  43. time += period.toSec();
  44. if (time == 0.0) {
  45. initial_position = robot_state.q_d;
  46. }
  47. double delta_angle = M_PI / 8.0 * (1 - std::cos(M_PI / 2.5 * time));
  48. franka::JointPositions output = {{initial_position[0], initial_position[1],
  49. initial_position[2], initial_position[3] + delta_angle,
  50. initial_position[4] + delta_angle, initial_position[5],
  51. initial_position[6] + delta_angle}};
  52. if (time >= 5.0) {
  53. std::cout << std::endl << "Finished motion, shutting down example" << std::endl;
  54. return franka::MotionFinished(output);
  55. }
  56. return output;
  57. });
  58. } catch (const franka::Exception& e) {
  59. std::cout << e.what() << std::endl;
  60. return -1;
  61. }
  62. return 0;
  63. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/947843
推荐阅读
相关标签
  

闽ICP备14008679号