Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
permocar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
Robert Hedman
permocar
Commits
bdd68ce4
Commit
bdd68ce4
authored
7 years ago
by
Robert Hedman
Browse files
Options
Downloads
Patches
Plain Diff
Small warning fixes
parent
d1f2103d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+12
-17
12 additions, 17 deletions
src/main.rs
with
12 additions
and
17 deletions
src/main.rs
+
12
−
17
View file @
bdd68ce4
...
@@ -11,10 +11,10 @@ use std::net::TcpListener;
...
@@ -11,10 +11,10 @@ use std::net::TcpListener;
extern
crate
serial
;
extern
crate
serial
;
use
std
::
io
;
use
std
::
io
;
use
std
::
time
::
Duration
;
use
std
::
time
::
Duration
;
use
std
::
io
::
prelude
::
*
;
//
use std::io::prelude::*;
use
serial
::
prelude
::
*
;
use
serial
::
prelude
::
*
;
use
std
::
str
;
//
use std::str;
// should the map matrix be two dim array of const size, vecs of dynamic, or what?
// should the map matrix be two dim array of const size, vecs of dynamic, or what?
...
@@ -34,7 +34,7 @@ fn main() {
...
@@ -34,7 +34,7 @@ fn main() {
thread
::
sleep
(
time
::
Duration
::
new
(
1
,
0
));
thread
::
sleep
(
time
::
Duration
::
new
(
1
,
0
));
loop
{
loop
{
match
stream
.read_exact
(
&
mut
message
)
{
match
stream
.read_exact
(
&
mut
message
)
{
Ok
(
msg
)
=>
{
println!
(
"server got: {} {}"
,
message
[
0
],
message
[
1
]);
Ok
(
_
)
=>
{
println!
(
"server got: {} {}"
,
message
[
0
],
message
[
1
]);
let
written_size
=
stream
.write
(
&
[
69
as
u8
,
96
as
u8
]);
let
written_size
=
stream
.write
(
&
[
69
as
u8
,
96
as
u8
]);
println!
(
"server wrote {:?} to stream."
,
written_size
);
println!
(
"server wrote {:?} to stream."
,
written_size
);
},
},
...
@@ -59,25 +59,21 @@ fn main() {
...
@@ -59,25 +59,21 @@ fn main() {
let
tracker
=
thread
::
spawn
(
move
||
{
let
tracker
=
thread
::
spawn
(
move
||
{
println!
(
"Tracker started."
);
println!
(
"Tracker started."
);
let
mut
serial
B
uf
:
[
u8
;
8
]
=
[
0
;
8
];
let
mut
serial
_b
uf
:
[
u8
;
8
]
=
[
0
;
8
];
let
device
=
String
::
from
(
"/dev/cu.usbmodem41"
);
let
device
=
String
::
from
(
"/dev/cu.usbmodem41"
);
let
mut
port
=
serial
::
open
(
&
device
)
.unwrap
();
let
mut
port
=
serial
::
open
(
&
device
)
.unwrap
();
interact
(
&
mut
port
)
.unwrap
();
interact
(
&
mut
port
)
.unwrap
();
let
mut
L
:
i32
=
0
;
let
mut
R
:
i32
=
0
;
let
mut
pos
:
(
i32
,
i32
)
=
(
0
,
0
);
let
mut
pos
:
(
i32
,
i32
)
=
(
0
,
0
);
loop
{
loop
{
// get encoder data from arduino and update local variables
// get encoder data from arduino and update local variables
match
port
.read_exact
(
&
mut
serial
B
uf
){
match
port
.read_exact
(
&
mut
serial
_b
uf
){
Ok
(
_
)
=>
{
Ok
(
_
)
=>
{
L
=
freq_to_distance
(
(
((
serialBuf
[
0
]
as
u32
)
<<
24
)
+
((
serialBuf
[
1
]
as
u32
)
<<
16
)
+
((
serialBuf
[
2
]
as
u32
)
<<
8
)
+
(
serialBuf
[
3
]
as
u32
)
)
as
i32
);
pos
.0
=
freq_to_distance
(
(
((
serial_buf
[
0
]
as
u32
)
<<
24
)
+
((
serial_buf
[
1
]
as
u32
)
<<
16
)
+
((
serial_buf
[
2
]
as
u32
)
<<
8
)
+
(
serial_buf
[
3
]
as
u32
)
)
as
i32
);
R
=
freq_to_distance
(
(
((
serialBuf
[
4
]
as
u32
)
<<
24
)
+
((
serialBuf
[
5
]
as
u32
)
<<
16
)
+
((
serialBuf
[
6
]
as
u32
)
<<
8
)
+
(
serialBuf
[
7
]
as
u32
)
)
as
i32
);
pos
.1
=
freq_to_distance
(
(
((
serial_buf
[
4
]
as
u32
)
<<
24
)
+
((
serial_buf
[
5
]
as
u32
)
<<
16
)
+
((
serial_buf
[
6
]
as
u32
)
<<
8
)
+
(
serial_buf
[
7
]
as
u32
)
)
as
i32
);
print!
(
"L: {}, "
,
L
);
print!
(
"L: {}, "
,
pos
.0
);
println!
(
"R: {}"
,
R
);
println!
(
"R: {}"
,
pos
.1
);
pos
.0
+=
L
;
pos
.1
+=
R
;
},
},
Err
(
e
)
=>
{
Err
(
e
)
=>
{
println!
(
"Could not read all bytes: {:?}"
,
e
);
println!
(
"Could not read all bytes: {:?}"
,
e
);
...
@@ -116,7 +112,7 @@ fn main() {
...
@@ -116,7 +112,7 @@ fn main() {
// set up connection to lidar
// set up connection to lidar
let
mut
stream
=
TcpStream
::
connect
(
"127.0.0.1:8080"
)
.unwrap
();
let
mut
stream
=
TcpStream
::
connect
(
"127.0.0.1:8080"
)
.unwrap
();
let
mut
lidar
B
uf
:
[
u8
;
2
]
=
[
0
;
2
];
let
mut
lidar
_b
uf
:
[
u8
;
2
]
=
[
0
;
2
];
// main loop for this thread
// main loop for this thread
loop
{
loop
{
...
@@ -133,9 +129,9 @@ fn main() {
...
@@ -133,9 +129,9 @@ fn main() {
let
stream_write_response
=
stream
.write
(
&
[
65
as
u8
,
66
as
u8
]);
let
stream_write_response
=
stream
.write
(
&
[
65
as
u8
,
66
as
u8
]);
println!
(
"mapper wrote {:?} to stream."
,
stream_write_response
);
println!
(
"mapper wrote {:?} to stream."
,
stream_write_response
);
match
stream
.read_exact
(
&
mut
lidar
B
uf
){
match
stream
.read_exact
(
&
mut
lidar
_b
uf
){
Ok
(
_
)
=>
{
Ok
(
_
)
=>
{
println!
(
"mapper got {}, {}, from lidar."
,
lidar
B
uf
[
0
],
lidar
B
uf
[
1
]);
println!
(
"mapper got {}, {}, from lidar."
,
lidar
_b
uf
[
0
],
lidar
_b
uf
[
1
]);
},
},
Err
(
e
)
=>
{
Err
(
e
)
=>
{
println!
(
"Could not read all bytes: {:?}"
,
e
);
println!
(
"Could not read all bytes: {:?}"
,
e
);
...
@@ -169,7 +165,6 @@ fn main() {
...
@@ -169,7 +165,6 @@ fn main() {
// pathfinder, takes a map and returns a list of nodes to aim for when driving
// pathfinder, takes a map and returns a list of nodes to aim for when driving
// This will be a function for mapper to call.
// This will be a function for mapper to call.
//
}
}
...
...
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