Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LidarLite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labrobotica
drivers
LidarLite
Commits
f969d0b8
Commit
f969d0b8
authored
8 years ago
by
asantamaria
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned 2 bytes reading function
parent
6e6d7d99
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/examples/lidar_lite_test.cpp
+1
-2
1 addition, 2 deletions
src/examples/lidar_lite_test.cpp
src/lidar_lite.cpp
+23
-40
23 additions, 40 deletions
src/lidar_lite.cpp
src/lidar_lite.h
+10
-0
10 additions, 0 deletions
src/lidar_lite.h
with
34 additions
and
42 deletions
src/examples/lidar_lite_test.cpp
+
1
−
2
View file @
f969d0b8
...
@@ -7,14 +7,13 @@ int main(int argc, char *argv[])
...
@@ -7,14 +7,13 @@ int main(int argc, char *argv[])
unsigned
char
device_id
=
0x62
;
unsigned
char
device_id
=
0x62
;
CLidarLite
*
laser_ptr
=
new
CLidarLite
(
device_id
,
serial
);
CLidarLite
*
laser_ptr
=
new
CLidarLite
(
device_id
,
serial
);
try
try
{
{
laser_ptr
->
open
();
laser_ptr
->
open
();
laser_ptr
->
open
();
laser_ptr
->
reset
();
laser_ptr
->
reset
();
laser_ptr
->
close
();
laser_ptr
->
close
();
}
catch
(
CLidarLiteException
&
e
)
}
catch
(
CLidarLiteException
&
e
)
{
{
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
...
...
This diff is collapsed.
Click to expand it.
src/lidar_lite.cpp
+
23
−
40
View file @
f969d0b8
...
@@ -9,7 +9,8 @@ CLidarLite::CLidarLite(const unsigned char &dev_id, const std::string &serial)
...
@@ -9,7 +9,8 @@ CLidarLite::CLidarLite(const unsigned char &dev_id, const std::string &serial)
CLidarLite
::~
CLidarLite
(
void
)
CLidarLite
::~
CLidarLite
(
void
)
{
{
close
();
if
(
this
->
status_
==
RUNNING
)
close
();
}
}
void
CLidarLite
::
write
(
unsigned
char
addr
,
unsigned
char
cmd
)
void
CLidarLite
::
write
(
unsigned
char
addr
,
unsigned
char
cmd
)
...
@@ -22,6 +23,9 @@ int CLidarLite::read(unsigned char addr, int len)
...
@@ -22,6 +23,9 @@ int CLidarLite::read(unsigned char addr, int len)
if
(
len
!=
1
&&
len
!=
2
)
if
(
len
!=
1
&&
len
!=
2
)
throw
CLidarLiteException
(
_HERE_
,
"Expected read data with invalid length. This function only allows to read 1 or 2 bytes"
);
throw
CLidarLiteException
(
_HERE_
,
"Expected read data with invalid length. This function only allows to read 1 or 2 bytes"
);
if
(
len
==
2
)
addr
=
addr_to_read_2bytes
(
addr
);
// See header file for a description of this functionality.
unsigned
char
data
[
len
];
unsigned
char
data
[
len
];
this
->
adapter_
->
write
(
this
->
dev_id_
,
&
addr
,
1
);
this
->
adapter_
->
write
(
this
->
dev_id_
,
&
addr
,
1
);
this
->
adapter_
->
read
(
this
->
dev_id_
,
data
,
len
);
this
->
adapter_
->
read
(
this
->
dev_id_
,
data
,
len
);
...
@@ -42,7 +46,7 @@ int CLidarLite::read(unsigned char addr, int len)
...
@@ -42,7 +46,7 @@ int CLidarLite::read(unsigned char addr, int len)
void
CLidarLite
::
open
(
void
)
void
CLidarLite
::
open
(
void
)
{
{
if
(
this
->
status_
!=
IDLE
)
if
(
this
->
status_
!=
IDLE
)
throw
CLidarLiteException
(
_HERE_
,
"Device cannot be OPEN
N
ED because it is already running."
);
throw
CLidarLiteException
(
_HERE_
,
"Device cannot be OPENED because it is already running."
);
try
try
{
{
...
@@ -55,56 +59,26 @@ void CLidarLite::open(void)
...
@@ -55,56 +59,26 @@ void CLidarLite::open(void)
std
::
cout
<<
" - Serial number: "
<<
this
->
serial_
<<
std
::
endl
;
std
::
cout
<<
" - Serial number: "
<<
this
->
serial_
<<
std
::
endl
;
std
::
cout
<<
" - Firmware revision: "
<<
(
int
)
this
->
adapter_
->
get_revision
()
<<
std
::
endl
;
std
::
cout
<<
" - Firmware revision: "
<<
(
int
)
this
->
adapter_
->
get_revision
()
<<
std
::
endl
;
// Set
up
gpio 2 and 3 as i2c
// Set gpio 2 and 3 as i2c
this
->
adapter_
->
config_gpio
(
gpio2
,
i2c
);
this
->
adapter_
->
config_gpio
(
gpio2
,
i2c
);
this
->
adapter_
->
config_gpio
(
gpio3
,
i2c
);
this
->
adapter_
->
config_gpio
(
gpio3
,
i2c
);
//
*******************
**************************
//
TEST WORK IN PROGRESS
**************************
// unsigned char cmd = 0x04;
// this->adapter_->write_reg(this->dev_id_, 0x00, &cmd, 1);
write
(
ACQ_COMMAND
,
0x04
);
write
(
ACQ_COMMAND
,
0x04
);
// unsigned char add = 0x01;
//Read STATUS. Repeat until bit 0 (LSB) goes low.
// int data_read;
//Read register 0x01. Repeat until bit 0 (LSB) goes low.
unsigned
char
busy
;
unsigned
char
busy
;
do
do
busy
=
read
(
0x01
,
1
);
busy
=
read
(
STATUS
,
1
);
while
(
busy
&
0x01
);
while
(
busy
&
0x01
);
// regular read example
// std::cout << "Register " << std::hex << ACQ_CONFIG_REG << " with value: " << read(ACQ_CONFIG_REG,1) << std::dec << std::endl;
// regular read
// read two bytes
// unsigned short int read_val;
std
::
cout
<<
"Lidar-Lite measurement: "
<<
read
(
FULL_DELAY_HIGH
,
2
)
<<
" cm"
<<
std
::
endl
;
// int len = 1;
// add = 0x04;
// unsigned char data_short[len];
// this->adapter_->write(this->dev_id_,&add,1);
// this->adapter_->read(this->dev_id_,data_short,len);
// read_val = data_short[0];
// std::cout << read_val << std::endl;
std
::
cout
<<
read
(
0x04
,
1
)
<<
std
::
endl
;
// double read
// len = 2;
// unsigned char data[len];
// add = 0x8f;
// this->adapter_->write(this->dev_id_,&add,1);
// this->adapter_->read(this->dev_id_,data,len);
// read_val = data[0]*256+data[1];
// std::cout << read_val << " cm" << std::endl;
std
::
cout
<<
read
(
0x8f
,
2
)
<<
" cm"
<<
std
::
endl
;
// ************************************************
// ************************************************
...
@@ -145,6 +119,9 @@ void CLidarLite::reset(void)
...
@@ -145,6 +119,9 @@ void CLidarLite::reset(void)
void
CLidarLite
::
blink_led
(
void
)
void
CLidarLite
::
blink_led
(
void
)
{
{
if
(
this
->
status_
!=
RUNNING
)
throw
CLidarLiteException
(
_HERE_
,
"Usb adapter LED will not BLINK because Lidar-Lite is not running."
);
try
try
{
{
for
(
int
ii
=
0
;
ii
<
2
;
++
ii
)
for
(
int
ii
=
0
;
ii
<
2
;
++
ii
)
...
@@ -159,3 +136,9 @@ void CLidarLite::blink_led(void)
...
@@ -159,3 +136,9 @@ void CLidarLite::blink_led(void)
throw
CLidarLiteException
(
_HERE_
,
e
.
what
());
throw
CLidarLiteException
(
_HERE_
,
e
.
what
());
}
}
}
}
unsigned
short
int
CLidarLite
::
addr_to_read_2bytes
(
unsigned
char
first_byte_addr
)
{
unsigned
short
int
val
=
(
0x01
<<
7
)
|
first_byte_addr
;
return
val
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/lidar_lite.h
+
10
−
0
View file @
f969d0b8
...
@@ -57,6 +57,16 @@ class CLidarLite
...
@@ -57,6 +57,16 @@ class CLidarLite
void
write
(
unsigned
char
addr
,
unsigned
char
cmd
);
void
write
(
unsigned
char
addr
,
unsigned
char
cmd
);
int
read
(
unsigned
char
addr
,
int
len
);
int
read
(
unsigned
char
addr
,
int
len
);
// Successive 2-byte readings (Autoincrement of address: A note about 0x8f vs 0x0f)
// Set the highest bit of any register to "1" if you set the high byte of a register
// and then take succesive readings from that register, then LIDAR-Lite automatically
// increments the register one for each read.
// An example: If we want to read the high and low bytes for the distance, we could
// take two single readings from 0x0f and 0x10, or we could take 2 byte read from
// register 0x8f. 0x8f = 10001111 and 0x0f = 00001111, meaning that 0x8f is 0x0f with
// the high byte set to "1", ergo it autoincrements.
unsigned
short
int
addr_to_read_2bytes
(
unsigned
char
first_byte_addr
);
public:
public:
CLidarLite
(
const
unsigned
char
&
dev_id
,
const
std
::
string
&
serial
);
CLidarLite
(
const
unsigned
char
&
dev_id
,
const
std
::
string
&
serial
);
~
CLidarLite
(
void
);
~
CLidarLite
(
void
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment