Energy harvesting mobile robot. Developed at Institute of Systems and Robotics — University of Coimbra.

Dependencies:   RF24

Dependents:   ISR_Mini-explorer_Rangefinder

Fork of ISR_Mini-explorer by ISR UC

Committer:
fabiofaria
Date:
Wed May 16 14:23:26 2018 +0000
Revision:
7:95bee84b6910
Parent:
5:43215ff15665
Bug fixed on read_radio.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fabiofaria 4:f6fddeae358e 1 #include "Rangefinder.h"
fabiofaria 4:f6fddeae358e 2 #include "mbed.h"
fabiofaria 4:f6fddeae358e 3
fabiofaria 4:f6fddeae358e 4 const int rgfAddr = 0x14;
fabiofaria 4:f6fddeae358e 5 uint16_t rgfMeasurements[16];
fabiofaria 5:43215ff15665 6 char sensors_selection[] = {1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}; // Only allows a maximum of 11 sensors simultaneously.
fabiofaria 4:f6fddeae358e 7
fabiofaria 4:f6fddeae358e 8 I2C* _i2c;
fabiofaria 4:f6fddeae358e 9 Mutex* _mutex;
fabiofaria 4:f6fddeae358e 10
fabiofaria 4:f6fddeae358e 11 void init_rangefinder(I2C* i2c_in, Mutex* mutex_in)
fabiofaria 4:f6fddeae358e 12 {
fabiofaria 4:f6fddeae358e 13 _i2c = i2c_in;
fabiofaria 4:f6fddeae358e 14 _mutex = mutex_in;
fabiofaria 4:f6fddeae358e 15 wait(1);
fabiofaria 4:f6fddeae358e 16 _mutex->lock();
fabiofaria 4:f6fddeae358e 17 _i2c->write(rgfAddr, sensors_selection, 16);
fabiofaria 4:f6fddeae358e 18 _mutex->unlock();
fabiofaria 4:f6fddeae358e 19 wait(1);
fabiofaria 4:f6fddeae358e 20 }
fabiofaria 4:f6fddeae358e 21
fabiofaria 4:f6fddeae358e 22 int read_rangefinder()
fabiofaria 4:f6fddeae358e 23 {
fabiofaria 4:f6fddeae358e 24 int i2c_result;
fabiofaria 4:f6fddeae358e 25
fabiofaria 4:f6fddeae358e 26 _mutex->lock();
fabiofaria 4:f6fddeae358e 27 i2c_result = _i2c->read(rgfAddr, (char*)rgfMeasurements, sizeof(rgfMeasurements));
fabiofaria 4:f6fddeae358e 28 _mutex->unlock();
fabiofaria 4:f6fddeae358e 29
fabiofaria 4:f6fddeae358e 30 return i2c_result;
fabiofaria 4:f6fddeae358e 31 }