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
b61a0566
Commit
b61a0566
authored
7 years ago
by
Robert Hedman
Browse files
Options
Downloads
Patches
Plain Diff
small const and fn updates
parent
13ae0608
Branches
Branches containing commit
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
+19
-8
19 additions, 8 deletions
src/main.rs
with
19 additions
and
8 deletions
src/main.rs
+
19
−
8
View file @
b61a0566
...
...
@@ -27,6 +27,11 @@ const LIDAR_BUF_SIZE: usize = 4096;
const
ROWS
:
usize
=
1000
;
const
COLS
:
usize
=
1000
;
// robot real stuff
const
AXEL_WIDTH
:
f32
=
175
;
// cm
const
FREQ_TO_OMEGA
:
f32
=
0.0002
;
const
WHEEL_RADIUS
:
f32
=
30.0
;
//cm
#![feature(box_syntax)]
fn
main
()
{
...
...
@@ -105,16 +110,17 @@ fn main() {
let
mut
port
=
serial
::
open
(
&
COUNTER_SERIAL_PORT
)
.unwrap
();
interact
(
&
mut
port
)
.unwrap
();
//let mut l_tick: f32 = 0;
//let mtu r_tick: f32 = 0;
let
mut
pos
:
(
i32
,
i32
,
f32
)
=
(
COLS
as
i32
/
2
,
ROWS
as
i32
/
2
,
0.0
);
println!
(
"location initial position: {:?}"
,
pos
);
loop
{
// get encoder data from arduino and update local variables
match
port
.read_exact
(
&
mut
serial_buf
){
Ok
(
_
)
=>
{
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
);
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
);
pos
.2
=
dist_to_angle
(
&
pos
);
let
l_speed
:
f32
=
tick_to_speed
(
(
((
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
);
let
r_speed
:
f32
=
tick_to_speed
(
(
((
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
);
pos
.2
=
update_state
(
&
pos
,
l_tick
,
r_tick
);
print!
(
"L: {}, "
,
pos
.0
);
println!
(
"R: {}"
,
pos
.1
);
},
...
...
@@ -259,12 +265,17 @@ fn interact<T: SerialPort>(port: &mut T) -> io::Result<()> {
Ok
(())
}
/*
const AXEL_WIDTH: f32 = 175; // cm
const FREQ_TO_OMEGA: f32 = 0.0002;
const WHEEL_RADIUS: f32 = 30.0; //cm
*/
fn
freq_to_distance
(
freq
:
i32
)
->
i
32
{
freq
/
10
fn
tick_to_speed
(
tick
:
i32
)
->
f
32
{
tick
/
10
.0
}
fn
dist_to_angl
e
(
pos
:
&
(
i
32
,
i
32
,
f32
)
)
->
f32
{
0.0
fn
update_stat
e
(
pos
:
&
(
f
32
,
f
32
,
f32
)
,
l_speed
:
f32
,
r_speed
:
f32
)
{
pos
.0
+=
0.5
;
}
fn
update_map_with_lidar
(
lidar_data
:
[
u8
;
LIDAR_BUF_SIZE
],
message_len
:
usize
,
map
:
&
mut
[[
u32
;
ROWS
];
COLS
])
{
map
[
0
][
0
]
+=
1
;
...
...
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