Project

General

Profile

Revision 1008

libsim rangefinders works with shared memory now

View differences:

rangefinder.c
25 25

  
26 26
#include "rangefinder.h"
27 27
#include "util.h"
28
#include "robot_shared.h"
28 29

  
30
extern RobotShared* shared_state;
31

  
29 32
/*
30 33
	read_distance returns the 8-bit reading from the rangefinder
31 34
	parameters:
......
55 58

  
56 59
void range_init(void)
57 60
{
58

  
61
	/* simulator does not need this */
59 62
}
60 63

  
61 64
int range_read_distance (int range_id)
62 65
{
63
	UNIMPLEMENTED
66
	int temp=0;
67
	/* read from array in shared memory, if valid */
68
	if (range_id > 0 && range_id < 6) {
69
		temp = (shared_state->ranges).d[range_id];
70
		if (temp < 0 || temp > 1000)
71
			return -1;
72
		else
73
			return temp;
74
	}
64 75
	return -1;
65 76
}
66 77

  

Also available in: Unified diff