Modules | Enumerations | Functions
Sharps

Functions which handle the IR-distance sensors. More...

Modules

 Advanced informations
 

Enumerations

enum  eSharpGet
 clusters select values for reading the distance measurements More...
 

Functions

int16_t sharps_toMm (uint16_t adc)
 Converts an adc value of a sharp sensor into millimeters. More...
 

Request Funktions

void sharps_request (eRequestType request)
 Requests new data from the sharp sensors. More...
 
uint8_t sharps_received (void)
 Indicates if new data for the data block sSharp was received. More...
 
uint8_t sharps_changed (void)
 Indicates if new data changed the data block sSharp. More...
 

Access Funktions

uint16_t sharps_get (eSharpGet select)
 Returns the last stored value of the selected sharp sensor. More...
 

Detailed Description

Functions which handle the IR-distance sensors.

Each sharp sensors returns an analog voltage which relates indirect to the measured distance. This voltage is converted with the internal analog-digital-converter.

example

/*******************************************************************************
* examples/sharp.c *
* ================ *
* *
* Version: 1.0.6 *
* Date : 15.11.17 *
* Author : Peter Weissig *
* *
* If you are changing this file, you may also consider to update *
* demos/diagnosticTool/diagnosticTool.c *
*******************************************************************************/
//*********************************<Included files>*****************************
#include <tucbot/tucbot.h>
//*********************************<Methods>************************************
void testSharp(void);
int main(void);
//*********************************[testSharp]**********************************
void testSharp(void) {
int16_t value;
uint8_t countdown = 0;
uint8_t flag_convert = 0xFF;
lcdclr();
lcdstr_p(PSTR("Sharp" ));
lcdxy(0,1);
lcdstr_p(PSTR(" #### #### ####"));
while (1) {
mdelay(100);
lcdxy(13,0);
lcdstr_p(PSTR( " mm"));
flag_convert = 0xFF;
countdown = 0;
} else if (buttons_get(kButtonRight)) {
mdelay(100);
lcdxy(13,0);
lcdstr_p(PSTR( "adc"));
flag_convert = 0x00;
countdown = 0;
}
if (countdown) {
countdown--;
} else {
countdown = 5;
if (flag_convert) {value = sharps_toMm(value);}
lcdxy( 1,1); int16tostr(lcdout,value,4);
if (flag_convert) {value = sharps_toMm(value);}
lcdxy( 6,1); int16tostr(lcdout,value,4);
if (flag_convert) {value = sharps_toMm(value);}
lcdxy(11,1); int16tostr(lcdout,value,4);
}
mdelay(100);
}
}
//*********************************[main]***************************************
int main (void) {
init_tucbot(0xFF);
testSharp();
return (0);
}

Enumeration Type Documentation

◆ eSharpGet

enum eSharpGet

clusters select values for reading the distance measurements

See also
sharps_get()
Enumerator
kSharpGetLeft 

constants (1): left ir-distance sensor

kSharpGetMiddle 

constants (2): middle ir-distance sensor

kSharpGetRight 

constants (3): right ir-distance sensor

Function Documentation

◆ sharps_changed()

uint8_t sharps_changed ( void  )

Indicates if new data changed the data block sSharp.

Because of noise the variables will probably be changed every time new data is received.

The return value is boolean.

Returns
8-bit unsigned integer which is a boolean value
See also
sharps_received(), sharps_request() and sharps_get()

◆ sharps_get()

uint16_t sharps_get ( eSharpGet  select)

Returns the last stored value of the selected sharp sensor.

This function relies on the internal data block sSharp - for new data use sharps_request().

The result is given in adc-units. It is helpful to convert the measurement into millimeters - see sharps_toMm().

Parameters
selectvalue of the selected sharp sensor - see also eSharpGet
Returns
16-bit unsigned integer (0..1023)
See also
sharps_request(), sharps_received() and sharps_changed()
Examples
sharp.c.

◆ sharps_received()

uint8_t sharps_received ( void  )

Indicates if new data for the data block sSharp was received.

The return value is boolean.

Returns
8-bit unsigned integer which is a boolean value
See also
sharps_changed(), sharps_request() and sharps_get()

◆ sharps_request()

void sharps_request ( eRequestType  request)

Requests new data from the sharp sensors.

For details on the request schema see The general request.

Involved data blocks are:
sSharp

See also
sharps_get(), sharps_received() and sharps_changed()
Examples
sharp.c.

◆ sharps_toMm()

int16_t sharps_toMm ( uint16_t  adc)

Converts an adc value of a sharp sensor into millimeters.

The function is just a rough conversion function. It was tuned to be a good fit to all sensors of all robots.

Parameters
adc16-bit unsigned integer
This is the measured value in adc-units.
Returns
16-bit integer (-2, -1, 80..800)
value description
-2 to far away (> 800mm)
-1 to close (< 80mm)
80..800 distance in mm
See also
sharps_get()
Examples
sharp.c.
leds_set
void leds_set(eLedMask bitmask, uint8_t bool)
Sets the selected leds on or off.
buttons_get
eButtonMask buttons_get(eButtonMask bitmask)
Returns the last stored value of the selected buttons.
kButtonMiddle
@ kButtonMiddle
bit mask (0x08): middle button
Definition: buttons.h:35
kSharpGetRight
@ kSharpGetRight
constants (3): right ir-distance sensor
Definition: sharps.h:88
kLedOn
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
kLedRight
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
kButtonRight
@ kButtonRight
bit mask (0x10): right button
Definition: buttons.h:37
buttons_request
void buttons_request(eRequestType request)
Requests new data from the buttons.
int16tostr
void int16tostr(void *out, int16_t number, uint8_t digits)
Converts an integer to a string and passes it to an output function.
sharps_get
uint16_t sharps_get(eSharpGet select)
Returns the last stored value of the selected sharp sensor.
kRequestContinuous
@ kRequestContinuous
constant (3): request continuous updates
Definition: update.h:37
kLedMiddle
@ kLedMiddle
bit mask (0x08): middle led
Definition: leds.h:44
kLedOff
@ kLedOff
constant (0x00): turn leds off
Definition: leds.h:61
kSharpGetLeft
@ kSharpGetLeft
constants (1): left ir-distance sensor
Definition: sharps.h:84
lcdclr
void lcdclr(void)
Clears the display.
sharps_toMm
int16_t sharps_toMm(uint16_t adc)
Converts an adc value of a sharp sensor into millimeters.
lcdxy
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
sharps_request
void sharps_request(eRequestType request)
Requests new data from the sharp sensors.
lcdstr_p
void lcdstr_p(const char *send_data)
Writes a string located in the flash to the display.
lcdout
void lcdout(uint8_t data)
Writes one byte to the display.
init_tucbot
void init_tucbot(uint8_t enable_interrupts)
Initiates the TUC-Bot.
mdelay
void mdelay(uint16_t mseconds)
Waits for the given time in milliseconds.
kSharpGetMiddle
@ kSharpGetMiddle
constants (2): middle ir-distance sensor
Definition: sharps.h:86