2 * Copyright Droids Corporation (2009)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: arm_xy.h,v 1.4 2009-11-08 17:25:00 zer0 Exp $
20 * Fabrice DESCLAUX <serpilliere@droids-corp.org>
21 * Olivier MATZ <zer0@droids-corp.org>
24 /* all static configuration for an arm */
26 void (*wrist_angle_deg2robot)(double wrist_edg,
29 void (*angle_rad2robot)(double shoulder_deg, double elbow_deg,
30 double *shoulder_out, double *elbow_out);
32 void (*angle_robot2rad)(double shoulder_robot, double elbow_robot,
33 double *shoulder_rad, double *elbow_rad);
35 /* ax12 identifiers */
39 /* related control system */
42 /* if true, don't apply to ax12 / cs */
46 /* request for a final position, in mm */
53 /* returned by arm_test_traj_end() */
54 #define ARM_TRAJ_END 0x01
55 #define ARM_TRAJ_NEAR 0x02
56 #define ARM_TRAJ_TIMEOUT 0x04
57 #define ARM_TRAJ_ERROR 0x08
59 #define ARM_TRAJ_ALL (ARM_TRAJ_END|ARM_TRAJ_TIMEOUT|ARM_TRAJ_ERROR)
60 #define ARM_TRAJ_ALL_NEAR (ARM_TRAJ_END|ARM_TRAJ_NEAR|ARM_TRAJ_TIMEOUT|ARM_TRAJ_ERROR)
61 #define ARM_TRAJ_END_NEAR (ARM_TRAJ_END|ARM_TRAJ_NEAR)
63 #define ARM_STATE_INIT 0
64 #define ARM_FLAG_MOVING 0x01 /* arm is currently moving */
65 #define ARM_FLAG_LAST_STEP 0x02 /* no more step is needed */
66 #define ARM_FLAG_IN_WINDOW 0x04 /* arm speed and pos are ok */
67 #define ARM_FLAG_TIMEOUT 0x08 /* too much time too reach pos */
68 #define ARM_FLAG_ERROR 0x10 /* error */
69 #define ARM_FLAG_FINISHED (ARM_FLAG_LAST_STEP | ARM_FLAG_IN_WINDOW)
71 /* Describes the current position of the arm. Mainly filled by
72 * arm_do_step(), arm_set_wrist(), arm_do_xy_cb(), ... */
74 /* current position */
78 /* wrist goal position (set once at init) */
79 int16_t wrist_angle_steps;
81 /* current angles in steps */
82 int32_t elbow_angle_steps;
83 int32_t shoulder_angle_steps;
85 /* current angles in radian */
86 double elbow_angle_rad;
87 double shoulder_angle_rad;
89 /* time before next update */
90 uint32_t next_update_time;
92 /* what speed to be applied, in specific speed unit */
93 uint32_t shoulder_speed;
96 volatile int8_t state; /* see list of flags above */
97 int8_t event; /* scheduler event, -1 if not running */
99 microseconds start_time; /* when we started that command */
100 microseconds wrist_reach_time; /* when the wrist should reach dest */
101 microseconds pos_reached_time; /* when last step is sent */
105 struct arm_config config;
106 struct arm_status status;
107 struct arm_request req;
110 extern struct arm left_arm;
111 extern struct arm right_arm;
113 uint8_t arm_test_traj_end(struct arm *arm, uint8_t mask);
114 uint8_t arm_wait_traj_end(struct arm *arm, uint8_t mask);
116 /* do a specific move to distance, height. This function _must_ be
117 * called from a context with a prio < ARM_PRIO to avoid any race
119 int8_t arm_do_xy(struct arm *arm, int16_t d_mm, int16_t h_mm, int16_t w_deg);
121 void arm_dump(struct arm *arm);
122 void arm_calibrate(void);