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: actuator.c,v 1.4 2009-04-24 19:30:41 zer0 Exp $
23 #include <aversive/pgmspace.h>
24 #include <aversive/wait.h>
25 #include <aversive/error.h>
30 #include <encoders_spi.h>
33 #include <scheduler.h>
38 #include <control_system_manager.h>
39 #include <blocking_detection_manager.h>
43 #include "../common/i2c_commands.h"
45 #include "ax12_user.h"
48 #define FINGER_DEBUG(args...) DEBUG(E_USER_FINGER, args)
49 #define FINGER_NOTICE(args...) NOTICE(E_USER_FINGER, args)
50 #define FINGER_ERROR(args...) ERROR(E_USER_FINGER, args)
59 static void finger_goto_cb(void *);
61 /* schedule a single event for the finger */
62 static void finger_schedule_event(struct finger *finger)
68 ret = scheduler_add_event(SCHEDULER_SINGLE,
69 (void *)finger_goto_cb,
73 FINGER_ERROR("Cannot load finger event");
80 static void finger_goto_cb(void *data)
83 struct finger *finger = data;
88 position = finger->destination;
90 FINGER_DEBUG("goto_cb %d", position);
91 ax12_user_write_int(&gen.ax12, FINGER_AX12,
92 AA_GOAL_POSITION_L, position);
95 /* load an event that will move the ax12 for us */
96 void finger_goto(uint16_t position)
99 FINGER_NOTICE("goto %d", position);
102 finger.destination = position;
103 if (finger.event != -1) {
105 return; /* nothing to do, event already scheduled */
108 finger_schedule_event(&finger);
111 static void finger_init(void)
114 finger.destination = 0;
118 uint16_t finger_get_goal_pos(void)
120 return finger.destination;
123 uint8_t finger_get_side(void)
125 if (finger.destination <= FINGER_CENTER)
126 return I2C_LEFT_SIDE;
127 return I2C_RIGHT_SIDE;
132 #define SERVO_LEFT_OUT 400
133 #define SERVO_LEFT_1LIN 520
134 #define SERVO_LEFT_2LIN 485
135 #define SERVO_RIGHT_OUT 290
136 #define SERVO_RIGHT_1LIN 155
137 #define SERVO_RIGHT_2LIN 180
139 void servo_lintel_out(void)
141 mechboard.servo_lintel_left = SERVO_LEFT_OUT;
142 mechboard.servo_lintel_right = SERVO_RIGHT_OUT;
145 void servo_lintel_1lin(void)
147 mechboard.servo_lintel_left = SERVO_LEFT_1LIN;
148 mechboard.servo_lintel_right = SERVO_RIGHT_1LIN;
151 void servo_lintel_2lin(void)
153 mechboard.servo_lintel_left = SERVO_LEFT_2LIN;
154 mechboard.servo_lintel_right = SERVO_RIGHT_2LIN;
159 void actuator_init(void)