2 * Copyright Droids Corporation, Microb Technology, Eirbot (2005)
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: robot_system.h,v 1.5.4.3 2008-04-06 17:33:57 zer0 Exp $
23 * The goal of this module is to provide an interface to motor and
24 * encoders of the robot. This module provide a function that returns
25 * the value of virtual encoders containing distance and angle. It
26 * also allow the user to command virtual angle and distance PWMs.
32 #include "angle_distance.h"
34 #ifndef _ROBOT_SYSTEM_H_
35 #define _ROBOT_SYSTEM_H_
39 #define RS_IGNORE_EXT_GAIN 2
40 #define RS_IGNORE_MOT_GAIN 4
47 #ifdef CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT
48 struct rs_polar pmot_prev;
49 struct rs_wheels wmot_prev;
54 int32_t (*left_mot_encoder)(void *);
55 void* left_mot_encoder_param;
58 int32_t (*right_mot_encoder)(void *);
59 void* right_mot_encoder_param;
63 struct rs_polar virtual_pwm;
64 struct rs_polar virtual_encoders;
66 struct rs_polar pext_prev;
67 struct rs_wheels wext_prev;
69 /* External encoders */
70 int32_t (*left_ext_encoder)(void *);
71 void* left_ext_encoder_param;
74 int32_t (*right_ext_encoder)(void *);
75 void* right_ext_encoder_param;
79 void (*left_pwm)(void *, int32_t);
81 void (*right_pwm)(void *, int32_t);
82 void *right_pwm_param;
85 /** Set the structure to 0 */
86 void rs_init( struct robot_system * );
90 #ifdef CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT
91 /** define ratio between mot and ext track. (track_mot / track_ext) */
92 void rs_set_ratio(struct robot_system * rs, double ratio);
95 /** define left PWM function and param */
96 void rs_set_left_pwm(struct robot_system * rs, void (*left_pwm)(void *, int32_t), void *left_pwm_param);
98 /** define right PWM function and param */
99 void rs_set_right_pwm(struct robot_system * rs, void (*right_pwm)(void *, int32_t), void *right_pwm_param);
101 #ifdef CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT
102 /** define left motor encoder function and param */
103 void rs_set_left_mot_encoder(struct robot_system * rs, int32_t (*left_mot_encoder)(void *),
104 void *left_mot_encoder_param, double gain);
106 /** define right motor encoder function and param */
107 void rs_set_right_mot_encoder(struct robot_system * rs, int32_t (*right_mot_encoder)(void *),
108 void *right_mot_encoder_param, double gain);
111 /** define left external encoder function and param */
112 void rs_set_left_ext_encoder(struct robot_system * rs, int32_t (*left_ext_encoder)(void *),
113 void *left_ext_encoder_param, double gain);
115 /** define right external encoder function and param */
116 void rs_set_right_ext_encoder(struct robot_system * rs, int32_t (*right_ext_encoder)(void *),
117 void *right_ext_encoder_param, double gain);
119 /**** Virtual encoders and PWM */
122 * set the real pwms according to the specified angle (it also
123 * depends on the last distance command sent)
125 void rs_set_angle(void * rs, int32_t angle);
128 * set the real pwms according to the specified distance (it also
129 * depends on the last angle command sent)
131 void rs_set_distance(void * rs, int32_t distance);
134 * get the virtual angle according to real encoders value.
136 int32_t rs_get_angle(void * rs);
139 * get the virtual distance according to real encoders value.
141 int32_t rs_get_distance(void * rs);
144 * get the angle according to ext encoders value.
146 int32_t rs_get_ext_angle(void * rs);
149 * get the distance according to ext encoders value.
151 int32_t rs_get_ext_distance(void * rs);
153 #ifdef CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT
155 * get the angle according to mot encoders value.
157 int32_t rs_get_mot_angle(void * rs);
160 * get the distance according to mot encoders value.
162 int32_t rs_get_mot_distance(void * rs);
165 /* same for left/right */
166 int32_t rs_get_ext_left(void * rs);
167 int32_t rs_get_ext_right(void * rs);
168 #ifdef CONFIG_MODULE_ROBOT_SYSTEM_MOT_AND_EXT
169 int32_t rs_get_mot_left(void * rs);
170 int32_t rs_get_mot_right(void * rs);
175 * Read the encoders, and update internal virtual counters. Call this
176 * function is needed before reading the virtual encoders. The program
177 * will decide if it the external encoders or the motor encoders are
178 * taken in account (depending on flags, but not yet)
180 void rs_update(void * rs);
182 void rs_set_flags(struct robot_system * rs, uint8_t flags);
185 #endif /* #ifndef _ROBOT_SYSTEM */