一、工业机器人编程
1. ABB机器人编程
plaintextMoveJ p20, v1000, z50, tool0;
p20
:目标点v1000
:速度1000mm/sz50
:转弯半径50mmtool0
:工具坐标系plaintextMoveL p20, v1000, z50, tool0;
p20
:目标点v1000
:速度1000mm/sz50
:转弯半径50mmtool0
:工具坐标系plaintextMoveJ ToPoint, Speed, Zone, Tool \[Wobj\];
ToPoint
:目标点名称Speed
:速度Zone
:转弯半径Tool
:工具坐标系Wobj
:工件坐标系plaintextMoveL p20, v1000, z50, tool0;
适用于工件的上下摆放,必须走直线,防止出现问题。
2. KUKA机器人编程
plaintextPTP {X 100, Y 200, Z 300, A 0, B 0, C 0}
X, Y, Z
:目标点的坐标A, B, C
:关节角度plaintextLIN {X 100, Y 200, Z 300, A 0, B 0, C 0} C_PTP
X, Y, Z
:目标点的坐标A, B, C
:关节角度C_PTP
:使用PTP模式进行直线运动plaintextCIRC {X 100, Y 200, Z 300, A 0, B 0, C 0} {X 200, Y 300, Z 400, A 0, B 0, C 0}
第一个点:圆弧的起始点
第二个点:圆弧的结束点
plaintextSET DO[1] = 1 SET AO[1] = 5.0
DO[1]
:数字输出信号AO[1]
:模拟输出信号plaintextSTOP CONTINUE
STOP
:停止机器人运动CONTINUE
:继续机器人运动plaintextRECORD PATH PLAY PATH
RECORD PATH
:记录机器人路径PLAY PATH
:播放记录的路径plaintext; 绕Z轴旋转90度 (2/2,0,0,2/2) 或 (0.7071,0,0,0.7071) ; 绕X轴旋转180度 (0,1,0,0) ; 绕Y轴旋转180度 (0,0,1,0) ; 绕Z轴旋转180度 (0,0,0,1)
四元数计算公式:一个四元数 (𝑤,𝑥,𝑦,𝑧) 可以通过旋转角度 𝜃 和旋转轴向量 (𝑢𝑥,𝑢𝑦,𝑢𝑧) 来计算。
二、ROS系统编程
1. ROS 2机器人编程
python# 发布者import rclpyfrom rclpy.node import Nodefrom std_msgs.msg import Stringclass MinimalPublisher(Node): def __init__(self): super().__init__('minimal_publisher') self.publisher = self.create_publisher(String, 'topic', 10) timer_period = 1.0 # seconds self.timer = self.create_timer(timer_period, self.timer_callback) self.i = 0 def timer_callback(self): msg = String() msg.data = 'Hello World: %d' % self.i self.publisher.publish(msg) self.get_logger().info('Publishing: "%s"' % msg.data) self.i += 1def main(args=None): rclpy.init(args=args) minimal_publisher = MinimalPublisher() rclpy.spin(minimal_publisher) minimal_publisher.destroy_node() rclpy.shutdown()if __name__ == '__main__': main()
python# 订阅者import rclpyfrom rclpy.node import Nodefrom std_msgs.msg import Stringclass MinimalSubscriber(Node): def __init__(self): super().__init__('minimal_subscriber') self.subscription = self.create_subscription( String, 'topic', self.listener_callback, 10) self.subscription # prevent unused variable warning def listener_callback(self, msg): self.get_logger().info('I heard: "%s"' % msg.data)def main(args=None): rclpy.init(args=args) minimal_subscriber = MinimalSubscriber() rclpy.spin(minimal_subscriber) minimal_subscriber.destroy_node() rclpy.shutdown()if __name__ == '__main__': main()
python# 服务端import rclpyfrom rclpy.node import Nodefrom example_interfaces.srv import AddTwoIntsclass MinimalService(Node): def __init__(self): super().__init__('minimal_service') self.srv = self.create_service(AddTwoInts, 'add_two_ints', self.add_two_ints_callback) def add_two_ints_callback(self, request, response): response.sum = request.a + request.b self.get_logger().info('Incoming request\na: %d b: %d' % (request.a, request.b)) return responsedef main(args=None): rclpy.init(args=args) minimal_service = MinimalService() rclpy.spin(minimal_service) rclpy.shutdown()if __name__ == '__main__': main()
python复制# 客户端import rclpyfrom rclpy.node import Nodefrom example_interfaces.srv import AddTwoIntsclass MinimalClientAsync(Node): def __init__(self): super().__init__('minimal_client_async') self.cli = self.create_client(AddTwoInts, 'add_two_ints') while not self.cli.wait_for_service(timeout_sec=1.0): self.get_logger().info('service not available, waiting again...') self.req = AddTwoInts.Request() def send_request(self, a, b): self.req.a = a self.req.b = b self.future = self.cli.call_async(self.req)def main(args=None): rclpy.init(args=args) minimal_client = MinimalClientAsync() minimal_client.send_request(40, 2) while rclpy.ok(): rclpy.spin_once(minimal_client) if minimal_client.future.done(): try: response = minimal_client.future.result()