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

Dependencies:   RF24

Fork of ISR_Mini-explorer by ISR UC

Committer:
fabiofaria
Date:
Thu Apr 19 15:35:29 2018 +0000
Revision:
4:560d24c0e5f8
Initial commit.

Who changed what in which revision?

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