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
LEGO Group 8
LEGO
Commits
ab5ee70b
Commit
ab5ee70b
authored
Apr 13, 2015
by
Casper
Browse files
Lesson6
parent
e80a9cd4
Changes
2
Hide whitespace changes
Inline
Side-by-side
lesson6/Vehicle1.java
0 → 100644
View file @
ab5ee70b
import
lejos.nxt.*
;
public
class
Vehicle1
{
static
SensorPort
port
=
SensorPort
.
S2
;
static
MotorPort
motorLeft
=
MotorPort
.
C
;
static
MotorPort
motorRight
=
MotorPort
.
B
;
static
int
raw
;
static
double
power
;
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
LCD
.
clear
();
while
(
true
)
{
raw
=
port
.
readRawValue
();
// Map 0 to 100
// power = 100.0 - ((100.0 / 1023.0) * raw);
// Map -100 to 100
power
=
100.0
-
((
100.0
/
1023.0
)
*
raw
)
*
2
;
motorLeft
.
controlMotor
((
int
)
power
,
MotorPort
.
FORWARD
);
motorRight
.
controlMotor
((
int
)
power
,
MotorPort
.
FORWARD
);
LCD
.
drawString
(
"Raw: "
,
0
,
0
);
LCD
.
drawInt
(
raw
,
4
,
0
,
1
);
LCD
.
drawString
(
"Power: "
,
0
,
2
);
LCD
.
drawInt
((
int
)
power
,
4
,
0
,
3
);
}
}
}
lesson6/Vehicle2a.java
0 → 100644
View file @
ab5ee70b
import
lejos.nxt.LCD
;
import
lejos.nxt.MotorPort
;
import
lejos.nxt.SensorPort
;
public
class
Vehicle2a
{
static
SensorPort
portLeft
=
SensorPort
.
S2
;
static
SensorPort
portRight
=
SensorPort
.
S3
;
static
MotorPort
motorLeft
=
MotorPort
.
C
;
static
MotorPort
motorRight
=
MotorPort
.
B
;
static
int
rawLeft
;
static
int
rawRight
;
static
double
powerLeft
;
static
double
powerRight
;
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
LCD
.
clear
();
while
(
true
)
{
rawLeft
=
portLeft
.
readRawValue
();
rawRight
=
portRight
.
readRawValue
();
powerLeft
=
100.0
-
((
100.0
/
1023.0
)
*
rawLeft
)
*
2
;
powerRight
=
100.0
-
((
100.0
/
1023.0
)
*
rawRight
)
*
2
;
motorLeft
.
controlMotor
((
int
)
powerLeft
,
MotorPort
.
FORWARD
);
motorRight
.
controlMotor
((
int
)
powerRight
,
MotorPort
.
FORWARD
);
LCD
.
drawString
(
"RawLeft: "
,
0
,
0
);
LCD
.
drawInt
(
rawLeft
,
4
,
0
,
1
);
LCD
.
drawString
(
"PowerLeft: "
,
0
,
2
);
LCD
.
drawInt
((
int
)
powerLeft
,
4
,
0
,
3
);
LCD
.
drawString
(
"RawRight: "
,
0
,
4
);
LCD
.
drawInt
(
rawRight
,
4
,
0
,
5
);
LCD
.
drawString
(
"PowerRight: "
,
0
,
6
);
LCD
.
drawInt
((
int
)
powerRight
,
4
,
0
,
7
);
}
}
}
Write
Preview
Supports
Markdown
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