Project

General

Profile

Revision 1037

added BOM to libsim and shared library

View differences:

branches/simulator/projects/simulator/libsim/bom.c
1
#include "bom.h"
2
#include "util.h"
1
#include "bom.h" 
2
#include "util.h" 
3
#include "robot_shared.h"
3 4

  
4
void bom_init(char type)
5
{
6
	UNIMPLEMENTED
5
#define BOM_VALUE_THRESHOLD 200 
6
#define NUM_BOM_LEDS 16
7

  
8
extern RobotShared *shared_state;
9

  
10
static char bom_type = BOM; void bom_init(char type) {
11
    bom_type = type;
12
    
13
    switch(bom_type) {
14
    case BOM:
15
        break;
16
    case BOM15:
17
        break;
18
    case RBOM:
19
        break;
20
    //default:
21
    }
7 22
}
8 23

  
9
void bom_refresh(int bitfield)
10
{
11
	UNIMPLEMENTED
24
void bom_refresh(int bitfield) {
25
	/* do nothing, since values are refreshed by simulator */
12 26
}
13 27

  
14
int bom_get(int which)
15
{
16
	UNIMPLEMENTED
17
	return -1;
28
int bom_get(int which) {
29
	return (shared_state->bom).led[which];
18 30
}
19 31

  
20
int bom_get_max(void)
21
{
22
	UNIMPLEMENTED
23
	return -1;
32
int bom_get_max(void) {
33
    int i, lowest_val, lowest_i;
34
    lowest_i = -1;
35
    lowest_val = 255;
36
    for(i = 0; i < NUM_BOM_LEDS; i++) {
37
        if(bom_get(i) < lowest_val) {
38
            lowest_val = bom_get(i);
39
            lowest_i = i;
40
        }
41
    }
42
    
43
    if(lowest_val < BOM_VALUE_THRESHOLD)
44
        return lowest_i;
45
    else
46
        return -1;
24 47
}
25 48

  
26
void bom_leds_on(int bit_field)
27
{
28
	UNIMPLEMENTED
49
void bom_leds_on(int bit_field) {
50
    switch(bom_type) {
51
    case BOM:
52
        if(bit_field == BOM_ALL) {
53
            (shared_state->bom).bom_on = 1;
54
        }
55
        break;
56
    case BOM15:
57
        //add bom 1.5 code here
58
        break;
59
    case RBOM:
60
        //add rbom code here
61
        break;
62
    }
29 63
}
30 64

  
31
void bom_leds_off(int bit_field)
32
{
33
	UNIMPLEMENTED
65
void bom_leds_off(int bit_field) {
66
    switch(bom_type) {
67
    case BOM:
68
        if(bit_field == BOM_ALL) {
69
            (shared_state->bom).bom_on = 0;
70
        }
71
        break;
72
    case BOM15:
73
        //add bom 1.5 code here
74
        break;
75
    case RBOM:
76
        //add rbom code here
77
        break;
78
    }
34 79
}
35 80

  
36
void bom_on(void)
37
{
38
	UNIMPLEMENTED
81
void bom_on(void) {
82
	bom_leds_on(BOM_ALL);
39 83
}
40 84

  
41
void bom_off(void)
42
{
43
	UNIMPLEMENTED
85
void bom_off(void) {
86
	bom_leds_off(BOM_ALL);
44 87
}
45

  
branches/simulator/projects/simulator/common/robot_shared.h
18 18
	short d[5];
19 19
} RangeFinder;
20 20

  
21
/* BOM has 16 leds, 0 - 15, with 0 pointing to the right
22
   increasing in index counterclockwise */
23
typedef struct BOMType
24
{
25
	short led[16];
26
	short bom_on;
27
} BOMs;
28

  
21 29
/* this is what is in the robot shared memory */
22 30
typedef struct RobotSharedType
23 31
{
24 32
	short motor1; /* motor1 value */
25 33
	short motor2; /* motor2 value */
26 34
	RangeFinder ranges; /* rangefinders */
35
	BOMs bom; /* BOM */
27 36
	/* add other sensors, etc here */
28 37
} RobotShared;
29 38

  

Also available in: Unified diff