Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
René Søndergaard Nilsson
LEGO
Commits
f93a8a48
Commit
f93a8a48
authored
Jun 09, 2015
by
René Nilsson
Browse files
Fix nasty GUI shit
parent
3481375c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Lesson10/Programs/PilotMonitor/src/PilotGUI.java
View file @
f93a8a48
...
...
@@ -17,15 +17,15 @@ import lejos.geom.Point;
import
lejos.robotics.navigation.Pose
;
public
class
PilotGUI
extends
JFrame
{
// program will automatically adjust if these three constants are changed
static
final
int
VIS_
HEIGHT
=
1
5
00
;
// visualization
height
static
final
int
VIS_WIDTH
=
150
0
;
// visualization
width
static
final
int
Y
_OFFSET
=
600
;
//
vertic
al offset to visualization
static
final
int
X_OFFSET
=
400
;
// horizontal offset to
visualization
static
final
int
POINT_WIDTH
=
4
;
// width of points shown in the visualization
// VIS_
HEIGHT
+ 2 *
Y
_OFFSET is the window
height
// VIS_WIDTH + 2 * X_OFFSET is the window width
static
final
int
VIS_HEIGHT
=
400
;
// visualization height
static
final
int
VIS_
WIDTH
=
1
0
00
;
// visualization
width
static
final
int
Y_OFFSET
=
3
0
;
//
vertical offset to
visualization
static
final
int
X
_OFFSET
=
600
;
//
horizont
al offset to visualization
static
final
int
POINT_WIDTH
=
4
;
// width of points shown in the
visualization
// VIS_HEIGHT + 2 * Y_OFFSET is the window height
// VIS_
WIDTH
+ 2 *
X
_OFFSET is the window
width
static
final
int
LENGTH_SCALE
=
5
;
...
...
@@ -68,9 +68,9 @@ public class PilotGUI extends JFrame {
super
.
paint
(
g
);
g2
.
setColor
(
Color
.
RED
);
//g2.drawRect(
X_OFFSET, Y_OFFSET
, VIS_WIDTH, VIS_HEIGHT);
g2
.
drawLine
(
0
,
X
_OFFSET
,
VIS_WIDTH
,
X
_OFFSET
);
g2
.
drawLine
(
Y_OFFSET
,
0
,
Y_OFFSET
,
VIS_HEIGH
T
);
//g2.drawRect(
winX(0), winY(VIS_HEIGHT)
, VIS_WIDTH, VIS_HEIGHT);
g2
.
drawLine
(
0
,
winY
(
Y_OFFSET
)+
Y
_OFFSET
,
VIS_WIDTH
+
2
*
X_OFFSET
,
winY
(
Y_OFFSET
)+
Y
_OFFSET
);
g2
.
drawLine
(
winX
(
0
),
0
,
winX
(
0
),
VIS_HEIGHT
*
2
+
2
*
Y_OFFSE
T
);
g2
.
setColor
(
Color
.
BLUE
);
int
x1
=
winX
(
0
),
y1
=
winY
(
0
),
x2
,
y2
;
...
...
@@ -78,8 +78,8 @@ public class PilotGUI extends JFrame {
for
(
int
i
=
1
;
i
<
size
;
i
++)
{
Point
current
=
route
.
get
(
i
);
x2
=
winX
((
int
)
current
.
getX
());
y2
=
winY
((
int
)
current
.
getY
());
x2
=
winX
((
int
)
current
.
getX
()
*
LENGTH_SCALE
);
y2
=
winY
((
int
)
current
.
getY
()
*
LENGTH_SCALE
);
g2
.
drawLine
(
x1
,
y1
,
x2
,
y2
);
x1
=
x2
;
y1
=
y2
;
}
...
...
@@ -88,8 +88,8 @@ public class PilotGUI extends JFrame {
{
p
=
particles
.
getParticle
(
i
).
getPose
();
g2
.
setColor
(
Color
.
BLACK
);
g2
.
fillRect
(
winX
((
int
)
p
.
getX
()-
POINT_WIDTH
/
2
)
,
winY
((
int
)
p
.
getY
()+
POINT_WIDTH
/
2
),
g2
.
fillRect
(
winX
((
int
)
p
.
getX
()
*
LENGTH_SCALE
-
POINT_WIDTH
/
2
)
,
winY
((
int
)
p
.
getY
()
*
LENGTH_SCALE
+
POINT_WIDTH
/
2
),
POINT_WIDTH
,
POINT_WIDTH
);
}
...
...
@@ -97,12 +97,12 @@ public class PilotGUI extends JFrame {
private
int
winX
(
int
x
)
{
return
x
*
LENGTH_SCALE
+
X_OFFSET
;
return
x
+
X_OFFSET
;
}
private
int
winY
(
int
y
)
{
return
VIS_HEIGHT
-
y
*
LENGTH_SCALE
+
Y_OFFSET
;
return
VIS_HEIGHT
-
y
+
Y_OFFSET
;
}
}
Lesson10/Programs/PilotMonitor/src/PilotMonitor.java
View file @
f93a8a48
...
...
@@ -12,6 +12,7 @@
import
lejos.robotics.navigation.Move
;
import
lejos.robotics.navigation.Pose
;
import
lejos.util.Delay
;
public
class
PilotMonitor
{
...
...
@@ -42,7 +43,7 @@ public class PilotMonitor
m
=
new
Move
(
(
type
==
0
)?
Move
.
MoveType
.
TRAVEL
:
Move
.
MoveType
.
ROTATE
,
distance
,
angle
,
false
);
System
.
out
.
println
(
"Move "
+
distance
+
" "
+
angle
);
return
m
;
return
new
Move
(
Move
.
MoveType
.
TRAVEL
,
50
,
0
,
false
)
;
}
public
void
go
()
...
...
@@ -55,6 +56,7 @@ public class PilotMonitor
view
.
update
(
route
.
getRoute
());
Pose
p
=
route
.
getCurrentPose
();
System
.
out
.
println
(
"Pose "
+
p
.
getX
()
+
" "
+
p
.
getY
()
+
" "
+
p
.
getHeading
());
Delay
.
msDelay
(
1000
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment