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
565e5e71
Commit
565e5e71
authored
Apr 20, 2015
by
Casper
Browse files
Merge branch 'master' of gitlab.au.dk:lego-group-8/lego
parents
faf95056
de0b0707
Changes
4
Hide whitespace changes
Inline
Side-by-side
lesson6/Vehicle2a.java
View file @
565e5e71
import
lejos.nxt.LCD
;
import
lejos.nxt.LightSensor
;
import
lejos.nxt.MotorPort
;
import
lejos.nxt.SensorPort
;
public
class
Vehicle2a
{
static
Sensor
Port
portLeft
=
SensorPort
.
S2
;
static
Sensor
Port
portRight
=
SensorPort
.
S3
;
static
MotorPort
motorLeft
=
MotorPort
.
C
;
static
MotorPort
motorRight
=
MotorPort
.
B
;
static
Light
Sensor
portLeft
=
new
LightSensor
(
SensorPort
.
S2
)
;
static
Light
Sensor
portRight
=
new
LightSensor
(
SensorPort
.
S3
)
;
static
MotorPort
motorLeft
=
MotorPort
.
B
;
static
MotorPort
motorRight
=
MotorPort
.
C
;
static
int
rawLeft
;
static
int
rawRight
;
static
double
powerLeft
;
...
...
@@ -14,12 +15,17 @@ public class Vehicle2a {
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
LCD
.
clear
();
portLeft
.
setFloodlight
(
false
);
portRight
.
setFloodlight
(
false
);
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
;
rawLeft
=
portLeft
.
readNormalizedValue
()
-
139
;
rawRight
=
portRight
.
readNormalizedValue
()
-
139
;
powerLeft
=
50.0
-
((
50.0
/
745.0
)
*
rawLeft
)
*
2
;
powerRight
=
50.0
-
((
50.0
/
745.0
)
*
rawRight
)
*
2
;
powerLeft
=
(
powerLeft
<
0
)
?
powerLeft
-
50
:
powerLeft
+
50
;
powerRight
=
(
powerRight
<
0
)
?
powerRight
-
50
:
powerRight
+
50
;
motorLeft
.
controlMotor
((
int
)
powerLeft
,
MotorPort
.
FORWARD
);
motorRight
.
controlMotor
((
int
)
powerRight
,
MotorPort
.
FORWARD
);
...
...
lesson6/Vehicle2b.java
0 → 100644
View file @
565e5e71
import
lejos.nxt.LCD
;
import
lejos.nxt.LightSensor
;
import
lejos.nxt.MotorPort
;
import
lejos.nxt.SensorPort
;
public
class
Vehicle2b
{
static
LightSensor
portLeft
=
new
LightSensor
(
SensorPort
.
S3
);
static
LightSensor
portRight
=
new
LightSensor
(
SensorPort
.
S2
);
static
MotorPort
motorLeft
=
MotorPort
.
B
;
static
MotorPort
motorRight
=
MotorPort
.
C
;
static
int
rawLeft
;
static
int
rawRight
;
static
double
powerLeft
;
static
double
powerRight
;
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
LCD
.
clear
();
portLeft
.
setFloodlight
(
false
);
portRight
.
setFloodlight
(
false
);
while
(
true
)
{
rawLeft
=
portLeft
.
readNormalizedValue
()
-
139
;
rawRight
=
portRight
.
readNormalizedValue
()
-
139
;
powerLeft
=
50.0
-
((
50.0
/
745.0
)
*
rawLeft
)
*
2
;
powerRight
=
50.0
-
((
50.0
/
745.0
)
*
rawRight
)
*
2
;
powerLeft
=
(
powerLeft
<
0
)
?
powerLeft
-
50
:
powerLeft
+
50
;
powerRight
=
(
powerRight
<
0
)
?
powerRight
-
50
:
powerRight
+
50
;
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
);
}
}
}
lesson6/Vehicle2c.java
0 → 100644
View file @
565e5e71
import
lejos.nxt.LCD
;
import
lejos.nxt.LightSensor
;
import
lejos.nxt.MotorPort
;
import
lejos.nxt.SensorPort
;
import
lejos.nxt.UltrasonicSensor
;
public
class
Vehicle2c
{
static
UltrasonicSensor
portLeft
=
new
UltrasonicSensor
(
SensorPort
.
S2
);
static
UltrasonicSensor
portRight
=
new
UltrasonicSensor
(
SensorPort
.
S3
);
static
MotorPort
motorLeft
=
MotorPort
.
B
;
static
MotorPort
motorRight
=
MotorPort
.
C
;
static
int
rawLeft
;
static
int
rawRight
;
static
double
powerLeft
=
75
;
static
double
powerRight
=
75
;
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
LCD
.
clear
();
while
(
true
)
{
rawLeft
=
portLeft
.
getDistance
();
rawRight
=
portRight
.
getDistance
();
powerLeft
=
0.625
*
rawRight
+
37.5
;
powerRight
=
0.625
*
rawLeft
+
37.5
;
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
);
}
}
}
lesson6/Vehicle3.java
0 → 100644
View file @
565e5e71
import
lejos.nxt.LCD
;
import
lejos.nxt.LightSensor
;
import
lejos.nxt.MotorPort
;
import
lejos.nxt.SensorPort
;
import
lejos.nxt.SoundSensor
;
import
lejos.nxt.UltrasonicSensor
;
public
class
Vehicle3
{
static
UltrasonicSensor
portLeft
=
new
UltrasonicSensor
(
SensorPort
.
S2
);
static
UltrasonicSensor
portRight
=
new
UltrasonicSensor
(
SensorPort
.
S3
);
static
SensorPort
soundLeft
=
SensorPort
.
S1
;
static
SensorPort
soundRight
=
SensorPort
.
S4
;
static
MotorPort
motorLeft
=
MotorPort
.
B
;
static
MotorPort
motorRight
=
MotorPort
.
C
;
static
int
rawDistanceLeft
;
static
int
rawDistanceRight
;
static
double
powerLeft
=
75
;
static
double
powerRight
=
75
;
static
int
rawSoundLeft
;
static
int
rawSoundRight
;
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
LCD
.
clear
();
soundLeft
.
setTypeAndMode
(
SensorPort
.
TYPE_SOUND_DB
,
SensorPort
.
MODE_PCTFULLSCALE
);
soundRight
.
setTypeAndMode
(
SensorPort
.
TYPE_SOUND_DB
,
SensorPort
.
MODE_PCTFULLSCALE
);
while
(
true
)
{
rawDistanceLeft
=
Math
.
min
(
100
,
portLeft
.
getDistance
());
rawDistanceRight
=
Math
.
min
(
100
,
portRight
.
getDistance
());
rawSoundLeft
=
soundLeft
.
readRawValue
();
rawSoundRight
=
soundRight
.
readRawValue
();
//powerLeft = 0.625 * rawDistanceRight + 37.5;
//powerRight = 0.625 * rawDistanceLeft + 37.5;
powerLeft
=
25
+
(
25.0
/
100.0
)
*
(
double
)
rawDistanceRight
;
powerRight
=
25
+
(
25.0
/
100.0
)
*
(
double
)
rawDistanceLeft
;
double
soundPowerLeft
=
25
+
(
25.0
/
1023.0
)
*
(
double
)
rawSoundLeft
;
double
soundPowerRight
=
25
+
(
25.0
/
1023.0
)
*
(
double
)
rawSoundRight
;
powerLeft
+=
soundPowerLeft
;
powerRight
+=
soundPowerRight
;
motorLeft
.
controlMotor
((
int
)
powerLeft
,
MotorPort
.
FORWARD
);
motorRight
.
controlMotor
((
int
)
powerRight
,
MotorPort
.
FORWARD
);
LCD
.
drawString
(
"SoundLeft: "
,
0
,
0
);
LCD
.
drawInt
((
int
)
rawSoundLeft
,
4
,
0
,
1
);
LCD
.
drawString
(
"PowerLeft: "
,
0
,
2
);
LCD
.
drawInt
((
int
)
powerLeft
,
4
,
0
,
3
);
LCD
.
drawString
(
"SoundRight: "
,
0
,
4
);
LCD
.
drawInt
((
int
)
rawSoundRight
,
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