Subversion Repositories shark

Rev

Rev 1637 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1624 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"
1647 giacomo 23
#include <drivers/shark_keyb26.h>
1624 giacomo 24
 
25
#include <servo.h>
1637 giacomo 26
//#include <drivers/udpip.h>
1624 giacomo 27
 
28
/* COM Port Constants */
29
#define COM_PORT COM1
30
#define COM_SPEED 115200
31
 
32
#define com(i) ((i) / 12) ? COM1 : COM2
33
#define pin(i) (i) % 12
34
 
35
/* Angle bounds */
36
#define POS_X_MIN          0
37
#define POS_X_MAX        200
38
#define POS_Y_MIN       -200
39
#define POS_Y_MAX        200
40
#define POS_Z_MIN       -150
41
#define POS_Z_MAX        150
42
 
43
typedef struct {
44
        int             adc_in;
45
        unsigned char   pwm;
46
} LEG_CFG_STATE;
47
 
48
typedef struct { /*describe the position of leg*/
49
        int             x;
50
        int             y;
51
        int             z;
52
} LEG_POS_STATE;
53
 
54
typedef struct { /*describe the servo angles*/
55
        int             a;
56
        int             b;
57
        int             c;
58
} LEG_ANG_STATE;
59
 
60
typedef struct {
61
        LEG_CFG_STATE   cfg[6];
62
        LEG_ANG_STATE   ang[6];
63
        char            power;
64
} HEXAPOD_STATE;
65
 
66
/*****************************************/
67
 
68
#define EVT_SET_MASK_LEG_ANGLE  0x01
69
 
70
#define EVT_STATUS_FREE         0x00
71
#define EVT_STATUS_WAIT         0x01
72
#define EVT_STATUS_EXEC         0x02
73
#define EVT_STATUS_DONE         0x03
74
 
75
struct action_event {
76
 
77
  unsigned char       type;
78
  unsigned char       status;
79
  struct timespec     time;
80
  unsigned char       mask;
81
  LEG_ANG_STATE       ang; //Servo angle data
82
  unsigned char       pwm;
83
  struct action_event *next;
84
 
85
};
86
 
87
struct action_event *get_first_old_event(struct timespec *time);
88
 
89
extern  sem_t           mx_status;
90
extern  HEXAPOD_STATE   status;
91
 
92
void    init_send(void);
93
void    end_send(void);
94
 
95
void    init_key(void);
96
 
97
/* Calibration */
98
 
99
void calibrate_init(void);
100
void calibrate_step(int step);
101
int adjust(int angle_sec, int leg, int num);
102
 
103
/* Actions */
104
 
105
int init_action_event(int number_of_events);
106
int insert_action_event(struct action_event *e);
107
int delete_action_event(int event);
108
struct action_event * get_first_old_event(struct timespec *time);
109
 
110
/* Tracer */
111
 
112
int trace_init(int buffer_size);
113
int trace_consumption(int sensor, int value);
114
int trace_send();
115