Subversion Repositories shark

Rev

Rev 1390 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1331 giacomo 1
/*
2
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 *
8
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
9
 *
10
 * http://www.sssup.it
11
 * http://retis.sssup.it
12
 * http://hartik.sssup.it
13
 */
14
 
15
#include <stdlib.h>
16
#include <string.h>
17
#include <math.h>
18
#include <kernel/kern.h>
19
#include <kernel/func.h>
20
#include <semaphore.h>
21
#include "modules/sem.h"
22
#include "modules/hartport.h"
1390 mauro 23
#include <drivers/keyb.h>
1331 giacomo 24
 
25
#include <servo.h>
26
 
27
/* COM Port Constants */
1359 giacomo 28
#define COM_PORT COM1
1331 giacomo 29
#define COM_SPEED 115200
30
 
1359 giacomo 31
#define com(i) ((i) / 12) ? COM1 : COM2
1331 giacomo 32
#define pin(i) (i) % 12
33
 
34
/* Angle bounds */
35
#define POS_X_MIN          0
36
#define POS_X_MAX        200
37
#define POS_Y_MIN       -200
38
#define POS_Y_MAX        200
39
#define POS_Z_MIN       -150
40
#define POS_Z_MAX        150
41
 
1333 giacomo 42
typedef struct {
43
        int             adc_in;
44
        unsigned char   pwm;
45
} LEG_CFG_STATE;
46
 
1336 giacomo 47
typedef struct { /*describe the position of leg*/
1331 giacomo 48
        int             x;
49
        int             y;
50
        int             z;
1333 giacomo 51
} LEG_POS_STATE;
1331 giacomo 52
 
1336 giacomo 53
typedef struct { /*describe the servo angles*/
1333 giacomo 54
        int             a;
55
        int             b;
56
        int             c;
57
} LEG_ANG_STATE;
58
 
1331 giacomo 59
typedef struct {
1333 giacomo 60
        LEG_CFG_STATE   cfg[6];
61
        LEG_ANG_STATE   ang[6];
1331 giacomo 62
        char            power;
63
} HEXAPOD_STATE;
64
 
65
/*****************************************/
66
 
1333 giacomo 67
#define EVT_SET_MASK_LEG_ANGLE  0x01
68
 
1396 giacomo 69
#define EVT_STATUS_FREE         0x00
1333 giacomo 70
#define EVT_STATUS_WAIT         0x01
71
#define EVT_STATUS_EXEC         0x02
72
#define EVT_STATUS_DONE         0x03
73
 
74
struct action_event {
75
 
76
  unsigned char       type;
77
  unsigned char       status;
78
  struct timespec     time;
79
  unsigned char       mask;
1336 giacomo 80
  LEG_ANG_STATE       ang; //Servo angle data
81
  unsigned char       pwm;
1333 giacomo 82
  struct action_event *next;
83
 
84
};
85
 
86
struct action_event *get_first_old_event(struct timespec *time);
87
 
1331 giacomo 88
extern  sem_t           mx_status;
89
extern  HEXAPOD_STATE   status;
90
 
91
void    init_send(void);
92
void    end_send(void);
93
 
94
void    init_key(void);
1336 giacomo 95
 
1337 giacomo 96
/* Calibration */
97
 
98
void calibrate_init(void);
99
void calibrate_step(int step);
1336 giacomo 100
int adjust(int angle_sec, int leg, int num);
101
 
1337 giacomo 102
/* Actions */
103
 
1396 giacomo 104
int init_action_event(int number_of_events);
1337 giacomo 105
int insert_action_event(struct action_event *e);
1396 giacomo 106
int delete_action_event(int event);
1337 giacomo 107
struct action_event * get_first_old_event(struct timespec *time);
108