Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hochautomatisiertes-Fahren
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Philipp Badenhoop
Hochautomatisiertes-Fahren
Commits
10becaba
Commit
10becaba
authored
6 years ago
by
duc anh vu
Browse files
Options
Downloads
Patches
Plain Diff
add sonar
parent
0fbf1f42
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/catkin_ws/src/car/include/ultrasonic/USS_SRF02.h
+21
-0
21 additions, 0 deletions
modules/catkin_ws/src/car/include/ultrasonic/USS_SRF02.h
modules/catkin_ws/src/car/src/ultrasonic/USS_SRF02.cpp
+63
-0
63 additions, 0 deletions
modules/catkin_ws/src/car/src/ultrasonic/USS_SRF02.cpp
with
84 additions
and
0 deletions
modules/catkin_ws/src/car/include/ultrasonic/USS_SRF02.h
0 → 100644
+
21
−
0
View file @
10becaba
#ifndef USS_SRF02_H_
#define USS_SRF02_H_
class
USS_SRF02
{
public:
USS_SRF02
(
int
devId
);
int
getDistance
();
private:
void
setup
();
int
devId
;
int
fd
;
};
#endif
/* USS_SRF02_H_ */
This diff is collapsed.
Click to expand it.
modules/catkin_ws/src/car/src/ultrasonic/USS_SRF02.cpp
0 → 100644
+
63
−
0
View file @
10becaba
#include
"../include/USS_SRF02.h"
#include
"../lib/wiringPi/wiringPi/wiringPiI2C.h"
#include
<iostream>
#include
<unistd.h>
//gpio pins where the sonar is connected
const
int
SRF02_SDA
=
8
;
//i2c data pin ;
const
int
SRF02_SCL
=
9
;
//i2c clock pin ;
// addresses of the sonars, the number is also as a sticker on the devices themselves
const
int
DEVICE_ADDRESS1
=
0x74
;
const
int
DEVICE_ADDRESS2
=
0x76
;
const
int
DEVICE_ADDRESS3
=
0x77
;
//path to i2c file
const
char
*
DEVICE
=
"/dev/i2c-1"
;
const
int
COMMAND_REGISTER
=
0x00
;
const
int
RESULT_HIGH_BYTE
=
0x02
;
const
int
RESULT_LOW_BYTE
=
0x03
;
const
int
RANGING_MODE_CM
=
0x51
;
const
int
DELAY
=
70
;
//70 ms for ranging to finish
int
main
()
{
USS_SRF02
uss
(
0x74
);
while
(
1
){
std
::
cout
<<
uss
.
getDistance
()
<<
std
::
endl
;
}
return
0
;
}
USS_SRF02
::
USS_SRF02
(
int
devId
)
{
this
->
fd
=
-
1
;
//no file opened yet
this
->
devId
=
devId
;
}
int
USS_SRF02
::
getDistance
()
{
int
distance
;
if
(
fd
==
-
1
){
USS_SRF02
::
setup
();
}
wiringPiI2CWriteReg8
(
fd
,
COMMAND_REGISTER
,
RANGING_MODE_CM
);
usleep
(
DELAY
*
1000
);
distance
=
wiringPiI2CReadReg16
(
fd
,
RESULT_LOW_BYTE
);
return
distance
;
}
void
USS_SRF02
::
setup
()
{
USS_SRF02
::
fd
=
wiringPiI2CSetupInterface
(
DEVICE
,
this
->
devId
);
//todo error handling,
//however wiringPiI2CSetupInterface() calls exit() if it fails
}
This diff is collapsed.
Click to expand it.
Preview
0%
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