upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for urm37.h:

API Description

An example using analog mode

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <signal.h>
#include "urm37.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
// Instantiate a URM37 sensor on analog pin A0, reset pin on D2,
// trigger pin on D3 with an analog reference voltage of 5.0
urm37_context sensor = urm37_init(0, 2, 3, 5.0, 0, true);
if (!sensor)
{
printf("urm37_init() failed.\n");
return(1);
}
// Every half a second, sample the URM37 and output the measured
// distance in cm.
while (shouldRun)
{
float distance;
urm37_get_distance(sensor, &distance, 0);
printf("Detected distance (cm): %f\n", distance);
upm_delay_ms(500);
}
printf("Exiting\n");
urm37_close(sensor);
return 0;
}

Interesting An example using UART mode

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <signal.h>
#include "urm37.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
// Instantiate a URM37 sensor on UART 0, with the reset pin on D2
urm37_context sensor = urm37_init(0, 2, 0, 0, 0, false);
if (!sensor)
{
printf("urm37_init() failed.\n");
return(1);
}
// Every half a second, sample the URM37 and output the measured
// distance in cm.
while (shouldRun)
{
float distance, temperature;
urm37_get_distance(sensor, &distance, 0);
printf("Detected distance (cm): %f\n", distance);
urm37_get_temperature(sensor, &temperature);
printf("Temperature (C): %f\n\n", temperature);
upm_delay_ms(500);
}
printf("Exiting\n");
urm37_close(sensor);
return 0;
}

Interesting

Go to the source code of this file.

Data Structures

struct  _urm37_context
 

Functions

urm37_context urm37_init (int a_pin, int reset_pin, int trigger_pin, float a_ref, int uart, bool analog_mode)
 
void urm37_close (urm37_context dev)
 
upm_result_t urm37_reset (urm37_context dev)
 
upm_result_t urm37_get_distance (urm37_context dev, float *distance, int degrees)
 
upm_result_t urm37_get_temperature (urm37_context dev, float *temperature)
 
upm_result_t urm37_read_eeprom (urm37_context dev, uint8_t addr, uint8_t *value)
 
upm_result_t urm37_write_eeprom (urm37_context dev, uint8_t addr, uint8_t value)
 
upm_result_t urm37_send_command (urm37_context dev, char *cmd, char *response)
 

Typedefs

typedef struct _urm37_contexturm37_context
 

Function Documentation

urm37_context urm37_init ( int  a_pin,
int  reset_pin,
int  trigger_pin,
float  a_ref,
int  uart,
bool  analog_mode 
)

URM37 Initializer

Parameters
a_pinAnalog pin to use. Ignored in UART mode.
reset_pinGPIO pin to use for reset
trigger_pinGPIO pin to use for triggering a distance measurement. Ignored in UART mode.
a_refThe analog reference voltage. Ignored in UART mode.
uartDefault UART to use (0 or 1). Ignored in analog mode.
modetrue for analog mode, false otherwise.

Here is the call graph for this function:

void urm37_close ( urm37_context  dev)

URM37 sensor close function

Here is the caller graph for this function:

upm_result_t urm37_reset ( urm37_context  dev)

Reset the device. This will take approximately 3 seconds to complete.

Parameters
devsensor context

Here is the caller graph for this function:

upm_result_t urm37_get_distance ( urm37_context  dev,
float *  distance,
int  degrees 
)

Get the distance measurement. A return value of 65535.0 in UART mode indicates an invalid measurement.

Parameters
devsensor context
distanceA pointer to a float that will contain the distance in CM if the measurement is successful.
degreesIn UART mode, this specifies the degrees to turn an attached PWM servo connected to the MOTO output on the URM37. Valid values are 0-270. This option is ignored in analog mode. If you are not using this functionality, just pass 0.
Returns
UPM status code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t urm37_get_temperature ( urm37_context  dev,
float *  temperature 
)

Get the temperature measurement. This is only valid in UART mode.

Parameters
devsensor context
temperatureA float pointer containing the measured temperature in degrees C
Returns
UPM status code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t urm37_read_eeprom ( urm37_context  dev,
uint8_t  addr,
uint8_t *  value 
)

In UART mode only, read a value from the EEPROM and return it.

Parameters
devsensor context
addrThe address in the EEPROM to read. Valid values are between 0x00-0x04.
valueA pointer containing the returned value.
Returns
UPM status code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t urm37_write_eeprom ( urm37_context  dev,
uint8_t  addr,
uint8_t  value 
)

In UART mode only, write a value into an address on the EEPROM.

Parameters
devsensor context
addrThe address in the EEPROM to write. Valid values are between 0x00-0x04.
valueThe value to write
Returns
UPM status code

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t urm37_send_command ( urm37_context  dev,
char *  cmd,
char *  response 
)

In UART mode only, send a 4-byte command, and return a 4-byte response.

Parameters
devsensor context
cmdA 4-byte command to transmit
responseThe 4-byte response
Returns
UPM response code (success, failure, or timeout)

Here is the caller graph for this function:

Typedef Documentation

typedef struct _urm37_context * urm37_context

device context