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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robert Hedman
permocar
Commits
a9caa438
Commit
a9caa438
authored
Nov 25, 2017
by
Robert Hedman
Browse files
Options
Downloads
Patches
Plain Diff
working serial branch
parent
07e87830
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Cargo.lock
+61
-0
61 additions, 0 deletions
Cargo.lock
Cargo.toml
+1
-0
1 addition, 0 deletions
Cargo.toml
src/main.rs
+41
-146
41 additions, 146 deletions
src/main.rs
with
103 additions
and
146 deletions
Cargo.lock
+
61
−
0
View file @
a9caa438
...
@@ -103,6 +103,14 @@ dependencies = [
...
@@ -103,6 +103,14 @@ dependencies = [
"adler32 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"adler32 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
]
[[package]]
name = "ioctl-rs"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
[[package]]
name = "jpeg-decoder"
name = "jpeg-decoder"
version = "0.1.13"
version = "0.1.13"
...
@@ -211,6 +219,7 @@ name = "rorientation"
...
@@ -211,6 +219,7 @@ name = "rorientation"
version = "0.1.0"
version = "0.1.0"
dependencies = [
dependencies = [
"image 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
]
[[package]]
[[package]]
...
@@ -223,6 +232,52 @@ name = "scopeguard"
...
@@ -223,6 +232,52 @@ name = "scopeguard"
version = "0.3.3"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serial"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serial-core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serial-unix 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serial-windows 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serial-core"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serial-unix"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ioctl-rs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"serial-core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serial-windows"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"serial-core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termios"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
[metadata]
"checksum adler32 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6cbd0b9af8587c72beadc9f72d35b9fbb070982c9e6203e46e93f10df25f8f45"
"checksum adler32 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6cbd0b9af8587c72beadc9f72d35b9fbb070982c9e6203e46e93f10df25f8f45"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
...
@@ -238,6 +293,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
...
@@ -238,6 +293,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum gif 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2e41945ba23db3bf51b24756d73d81acb4f28d85c3dccc32c6fae904438c25f"
"checksum gif 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2e41945ba23db3bf51b24756d73d81acb4f28d85c3dccc32c6fae904438c25f"
"checksum image 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d1576ffa01849c91b484b95c01d54dddc242b4d50923eaa2d4d74a58c4b9e8fd"
"checksum image 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d1576ffa01849c91b484b95c01d54dddc242b4d50923eaa2d4d74a58c4b9e8fd"
"checksum inflate 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10ec05638adf7c5c788bc0cfa608cd479a13572beda20feb4898fe1d85d2c64b"
"checksum inflate 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10ec05638adf7c5c788bc0cfa608cd479a13572beda20feb4898fe1d85d2c64b"
"checksum ioctl-rs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f7970510895cee30b3e9128319f2cefd4bde883a39f38baa279567ba3a7eb97d"
"checksum jpeg-decoder 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2805ccb10ffe4d10e06ef68a158ff94c255211ecbae848fbde2146b098f93ce7"
"checksum jpeg-decoder 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2805ccb10ffe4d10e06ef68a158ff94c255211ecbae848fbde2146b098f93ce7"
"checksum lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "236eb37a62591d4a41a89b7763d7de3e06ca02d5ab2815446a8bae5d2f8c2d57"
"checksum lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "236eb37a62591d4a41a89b7763d7de3e06ca02d5ab2815446a8bae5d2f8c2d57"
"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2"
"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2"
...
@@ -253,3 +309,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
...
@@ -253,3 +309,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53"
"checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53"
"checksum scoped_threadpool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4ea459fe3ceff01e09534847c49860891d3ff1c12b4eb7731b67f2778fb60190"
"checksum scoped_threadpool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4ea459fe3ceff01e09534847c49860891d3ff1c12b4eb7731b67f2778fb60190"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum serial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a1237a96570fc377c13baa1b88c7589ab66edced652e43ffb17088f003db3e86"
"checksum serial-core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f46209b345401737ae2125fe5b19a77acce90cd53e1658cda928e4fe9a64581"
"checksum serial-unix 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f03fbca4c9d866e24a459cbca71283f545a37f8e3e002ad8c70593871453cab7"
"checksum serial-windows 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15c6d3b776267a75d31bbdfd5d36c0ca051251caafc285827052bc53bcdc8162"
"checksum termios 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d9cf598a6d7ce700a4e6a9199da127e6819a61e64b68609683cc9a01b5683a"
This diff is collapsed.
Click to expand it.
Cargo.toml
+
1
−
0
View file @
a9caa438
...
@@ -5,3 +5,4 @@ authors = ["Robert Hedman <robert.hedman@mac.com>"]
...
@@ -5,3 +5,4 @@ authors = ["Robert Hedman <robert.hedman@mac.com>"]
[dependencies]
[dependencies]
image
=
"*"
image
=
"*"
serial
=
"0.4"
This diff is collapsed.
Click to expand it.
src/main.rs
+
41
−
146
View file @
a9caa438
use
std
::
thread
;
extern
crate
serial
;
use
std
::
sync
::
mpsc
;
use
std
::
time
;
// stuff for tcp
//use std::env;
use
std
::
io
::
prelude
::
*
;
use
std
::
io
;
use
std
::
net
::
TcpStream
;
use
std
::
time
::
Duration
;
use
std
::
net
::
TcpListener
;
use
std
::
str
;
// should the map matrix be two dim array of const size, vecs of dynamic, or what?
use
std
::
io
::
prelude
::
*
;
const
ROWS
:
usize
=
50
;
use
serial
::
prelude
::
*
;
const
COLS
:
usize
=
100
;
fn
main
()
{
fn
main
()
{
let
mut
map
=
[[
0u32
;
ROWS
];
COLS
];
map
[
0
][
0
]
=
3
;
println!
(
"{}, {}"
,
map
[
0
][
0
],
map
[
0
][
1
]);
let
(
request_location_tx
,
request_location_rx
):
(
mpsc
::
Sender
<
bool
>
,
mpsc
::
Receiver
<
bool
>
)
=
mpsc
::
channel
();
let
(
send_location_tx
,
send_location_rx
):
(
mpsc
::
Sender
<
(
i32
,
i32
)
>
,
mpsc
::
Receiver
<
(
i32
,
i32
)
>
)
=
mpsc
::
channel
();
// location tracker
let
tracker
=
thread
::
spawn
(
move
||
{
println!
(
"Tracker started."
);
let
mut
pos
:
(
i32
,
i32
)
=
(
0
,
0
);
loop
{
// get encoder data from arduino
let
mut
t
:
i32
=
0
;
for
_
in
0
..
1000
{
t
=
t
+
1
;
};
for
_
in
0
..
1000
{
t
=
t
-
1
;
};
// update local variables
// check if position is requested
match
request_location_rx
.try_recv
()
{
Ok
(
msg
)
=>
{
if
msg
==
false
{
println!
(
"tracker got stop signal."
);
break
;
};
send_location_tx
.send
(
pos
)
.unwrap
();
pos
.0
+=
1
;
},
Err
(
_
)
=>
{
//println!("Error: {}, on recieving side.", e);
//thread::sleep_ms(100);
pos
.1
+=
1
;
},
};
};
println!
(
"tracker exiting with local pos: {:?}"
,
pos
);
});
// mapper (gets lidar data, requests position and updates its map.)
let
mapper
=
thread
::
spawn
(
move
||
{
println!
(
"mapper started."
);
// create empty map
let
mut
pos
:
(
i32
,
i32
);
//= (0,0);
loop
{
// request position data
request_location_tx
.send
(
true
)
.unwrap
();
pos
=
send_location_rx
.recv
()
.unwrap
();
if
pos
.0
%
1000
==
0
{
println!
(
"mapper pos: {:?} "
,
pos
);
};
let
device
=
String
::
from
(
"/dev/cu.usbmodem1411"
);
let
mut
port
=
serial
::
open
(
&
device
)
.unwrap
();
interact
(
&
mut
port
)
.unwrap
();
// request lidar data
// update map
if
pos
.0
==
2000
{
println!
(
"mapper done."
);
request_location_tx
.send
(
false
)
.unwrap
();
break
;
}
}
//thread::sleep(time::Duration::new(0,50*1000000)); // from ms to ns
};
});
fn
interact
<
T
:
SerialPort
>
(
port
:
&
mut
T
)
->
io
::
Result
<
()
>
{
try
!
(
port
.reconfigure
(
&
|
settings
|
{
try
!
(
settings
.set_baud_rate
(
serial
::
Baud9600
));
settings
.set_char_size
(
serial
::
Bits8
);
settings
.set_parity
(
serial
::
ParityNone
);
settings
.set_stop_bits
(
serial
::
Stop1
);
settings
.set_flow_control
(
serial
::
FlowNone
);
Ok
(())
}));
try
!
(
port
.set_timeout
(
Duration
::
from_millis
(
10000
)));
let
server
=
thread
::
spawn
(||
{
//let mut buf: Vec<u8> = (0..255).collect();
let
listener
=
TcpListener
::
bind
(
"127.0.0.1:8080"
)
.unwrap
();
let
mut
stream
;
let
mut
message
=
[
0u8
;
128
];
match
listener
.accept
()
{
Ok
((
socket
,
addr
))
=>
{
println!
(
"server: new client: {:?}"
,
addr
);
stream
=
socket
;
thread
::
sleep
(
time
::
Duration
::
new
(
1
,
0
));
loop
{
match
stream
.read
(
&
mut
message
)
{
Ok
(
msg
)
=>
{
println!
(
"server got: {:?}, local message: {}"
,
msg
,
str
::
from_utf8
(
&
message
)
.unwrap
());
let
written_size
=
stream
.write_all
(
"Server says hi.
\n
"
.as_bytes
());
println!
(
"server wrote_all {:?} to stream."
,
written_size
);
},
Err
(
e
)
=>
{
println!
(
"Some error in readToString in swerver: {}"
,
e
)},
}
}
},
Err
(
e
)
=>
println!
(
"couldn't get client: {:?}"
,
e
),
}
});
thread
::
sleep
(
time
::
Duration
::
new
(
3
,
0
));
let
mut
stream
=
TcpStream
::
connect
(
"127.0.0.1:8080"
)
.unwrap
();
//thread::sleep(time::Duration::new(0,900*1000000));
//let written_size = stream.write(&['y' as u8,'o' as u8, '!' as u8]);
//println!("main wrote {:?} bytes to stream.", written_size);
let
written_size
=
stream
.write_all
(
"Main says hi."
.as_bytes
())
;
let
mut
buf
:
[
u8
;
255
]
=
[
0
;
255
]
;
println!
(
"main wrote_all {:?} to stream."
,
written_size
)
;
let
mut
count
:
usize
=
0
;
let
mut
stream_copy
=
stream
.try_clone
()
.unwrap
();
for
c
in
port
.bytes
()
{
let
mut
c
:
u8
=
0
;
match
c
{
for
b
in
stream
.bytes
()
{
Ok
(
c
)
=>
{
match
b
{
buf
[
count
]
=
c
;
Ok
(
byte
)
=>
{
print!
(
"{}"
,
byte
as
char
)
;
count
+=
1
;
if
c
==
14
{
if
c
as
char
==
'\n'
{
c
=
0
;
for
i
in
0
..
count
{
let
_
=
stream_copy
.write_all
(
"Hi Server, Me Main, got your message!"
.as_bytes
()
);
print!
(
"{}"
,
buf
[
i
]
as
char
);
}
}
else
{
count
=
0
;
c
+=
1
;
}
}
},
},
Err
(
_
)
=>
{}
,
Err
(
e
)
=>
println!
(
"{:?}"
,
e
)
,
}
}
;
}
}
Ok
(())
println!
(
"Main wating for join."
);
mapper
.join
()
.unwrap
();
tracker
.join
()
.unwrap
();
println!
(
"Main wating for server join."
);
//drop(stream);
server
.join
()
.unwrap
();
println!
(
"end of main"
);
// pathfinder, takes a map and returns a list of nodes to aim for when driving
// This will be a function for mapper to call.
//
}
}
\ No newline at end of file
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