summaryrefslogtreecommitdiff
path: root/digital/beacon/src/servo.h
blob: 7eda81fddceb1338cb78fea70824a805dec79562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* servo.h */
/* Beacon servomotor management. {{{
 *
 * Copyright (C) 2012 Florent Duchon
 *
 * APBTeam:
 *        Web: http://apbteam.org/
 *      Email: team AT apbteam DOT org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * }}} */

#ifndef _SERVO_H
#define _SERVO_H

#define SERVO_ANGLE_MIN 	69
#define SERVO_ANGLE_MAX 	254

#define SERVO_ANGLE_POSITION_TOLERANCE 	5

#define WAVE_TASK_PERIOD 	15L
#define SERVO_WAVE_OFFSET 	(uint16_t)6


#define SERVO_1_ANGLE_POSITION 			0
#ifdef LOL_NUMBER_3
#define SERVO_2_ANGLE_POSITION 			270
#else
#define SERVO_2_ANGLE_POSITION 			90
#endif


#define RISING			1
#define FALLING			-1

/* SERVO ID */
typedef enum
{
	SERVO_1,
	SERVO_2
} TServo_ID;

typedef enum
{
	SERVO_SCANNING_OFF,
	SERVO_SCANNING_FAST_IN_PROGRESS,
	SERVO_SCANNING_FAST_FINISHED,
	SERVO_SCANNING_SLOW_IN_PROGRESS,
	SERVO_SCANNING_SLOW_FINISHED
} TServo_state;

typedef struct
{
	TServo_ID id;
	int16_t top;
	int16_t bottom;
	int scanning_sense;
	TServo_state state;
} servo_s;

/* This function initializes the servo structures */
void servo_structure_init(void);

/* This function initializes low and high level modules for servos */
void servo_init(void);

/* This function initializes the timer used for servomotor signal generation */
void servo_timer1_init(void);

/* This function increases by one unit the angle of the defined servo and returns "angle" value */
int16_t servo_angle_increase(TServo_ID servo_id);

/* This function decreases by one unit the angle of the defined servo and returns "angle" value */
int16_t servo_angle_decrease(TServo_ID servo_id);

/* This function returns the "angle" value of a defined servo */
int16_t servo_get_value(TServo_ID servo_id);

/* This function sets the "angle" value of a defined servo */
int16_t servo_set_value(TServo_ID servo_id,int16_t value);

/* This function returns the current state of a defined servo */
TServo_state servo_get_state(TServo_ID servo_id);

/* This function updates the state of a defined servo */
void servo_set_state(TServo_ID servo_id,TServo_state state);

/* This function returns the scanning sens of the defined servo */
int8_t servo_get_scanning_sense(TServo_ID servo_id);

/* This function inverses the scanning sense of the servo */
void servo_inverse_scanning_sense(TServo_ID servo_id);

/* This function generates a wave scanning */
void servo_waveform_scanning(TServo_ID servo_id, uint8_t average_value);

/* Wave Task */
void servo_wave_task(void);

/* Start wave task */
void servo_start_wave_task(void);

/* Stop wave task */
void servo_stop_wave_task(void);

#endif