Skip to content

Instantly share code, notes, and snippets.

@incheon incheon/Task11.java
Created Nov 24, 2015

Embed
What would you like to do?
移動ロボット1週目の課題の解答です。
package client;
public class Task11 extends NeoControlNomad2 {
public static void main(String args[]) {
new Task11();
}
public Task11() {
doProgramming();
}
public void doProgramming() {
connect_robot(1);
while (true) {
scout_vm(100, 0); // その場で回転
}
// disconnect_robot(1);
}
}
package client;
public class Task12 extends NeoControlNomad2 {
private final int THRESHOLD = 100; // 減速を始める限界の距離
public static void main(String args[]) {
new Task12();
}
public Task12() {
doProgramming();
}
public void doProgramming() {
connect_robot(1);
while (true) {
int frontDistance = State[17]; // 前方の壁との距離を取得
int speedFront; // 前進スピード
int speedRotate; // 回転スピード
if (frontDistance < THRESHOLD) {
speedFront = 20; // 壁が近くなったら減速
speedRotate = 100; // 壁が近くなったら回転
} else {
speedFront = 200;
speedRotate = 0;
}
scout_vm(speedFront, speedRotate);
}
}
// disconnect_robot(1);
}
package client;
public class Task13 extends NeoControlNomad2 {
public static void main(String args[]) {
new Task13();
}
public Task13() {
doProgramming();
}
public void doProgramming() {
connect_robot(1);
while (true) {
int frontDistance = State[17]; // 前方の壁との距離を取得
int properDistance = 50; // 障害物との適切な距離
int acceptableRange = 5; // ぴったりには泊まれないので目標との前後差を許容する
int speedFront; // 前進スピード
if (frontDistance > properDistance) {
speedFront = 150;
// } else if(distFront == properDistance) { これは失敗(ぴったりには止まれない)
} else if (frontDistance > properDistance - acceptableRange
&& frontDistance < properDistance + acceptableRange) { // これが正解
speedFront = 0;
} else {
speedFront = -50;
}
scout_vm(speedFront, 0);
}
}
// disconnect_robot(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.