Date: 23rd of May 2013
Participating group members: Kenneth Baagøe, Morten D. Bech and Thomas Winding
Activity duration: 7 hours
Goal
Further refining the player robot described in previous entry[9] and possibly start constructing the autonomous robots for the game.
Plan
Identify the bug that we noticed last time that caused problems with attacking and fix it. Add the video feed from the player robot directly into the Java controller application that runs on the PC. Possibly start developing the program for the autonomous robots and building them.
Progress
Controlling the robot
The problem with the robot being unable to attack when steering left while moving forward or steering right while moving backwards stumped us last time. The solution, however, was not very complicated and can be explained by with the term key blocking/ghosting[1][2]. Key blocking basically means that a keyboard can only handle three keypresses at a time and while that was what we were trying to do, it is only certain combinations it could handle, which we inadvertently demonstrated: When pressing e.g. the left arrow and the up arrow the channel that the space bar was trying to send on was blocked. Finally we solved the problem by moving the controls from the arrow keys to the WASD keys which did not cause blocking in the keyboard.
Video feed in the Java application
We tried to add the video feed from an Android smartphone directly into the Java controller application that runs on the PC. We were able to get a feed running using the media functionality of JavaFX and we tried using the VLCj library[3] that utilize the streaming functionality of the VLC media player[4]. On the smartphone we used the applications IP webcam[5] and spydroid[6].
As mentioned we were able to get a feed running using the JavaFX library, this was done in combination with IP webcam application for the smartphone, see code below. We had to set up a LAN as the application was only able to stream on a local network. The problem we encountered with this solution was that there was a very noticable delay on the feed, 3-4 seconds. Unfortunately we were not able to figure out a way to circumvent this delay and thus the solution was not usable as a delay that long made it too hard to control the robot properly.
Video feed in Java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.media.Media; import javafx.scene.media.MediaView; import javafx.stage.Stage; public class MediaPlayer extends Application { private static final String MEDIA_URL = "http://192.168.10.101:8080"; public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("JavaFX Media Player"); Group root = new Group(); Scene scene = new Scene(root, 640, 480); Media media = new Media(MEDIA_URL); javafx.scene.media.MediaPlayer mediaPlayer = new javafx.scene.media.MediaPlayer(media); mediaPlayer.setAutoPlay(true); MediaView mediaView = new MediaView(mediaPlayer); ((Group)scene.getRoot()).getChildren().add(mediaView); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } |
We also tried using the spydroid application in conjunction with the VLCj library but were unable to get the video feed running in Java, it would connect but there would be no picture. When we opened the stream in a browser instead, we saw that this application had a delay comparable to the one described above. Thus we chose to not pursue the use of this application any more.
Autonomous robots
We started developing the program for the autonomous robots and decided that they should be motivation based[8]. We had a good idea of how the robots should function and thus we needed to translate that into different behaviors for the robots. The behaviors included:
– When the robot was “idle”
– When the robot was hungry
– When the robot had been hit by the player robot
– When the robot saw the player robot
– When the robot saw an obstacle / other autonomous robot
As we had done motivation based robots before[7] we were able to draw inspiration from the program we developed then and reused the arbitrator and behavior interface.
We added a simple idle behavior that rotated the robot in place and added the behavior that made robot scared when it saw the player robot so we could test the IR receiver which we wanted to use to detect the player robot. The takeControl()
would then return a high value when the robot is relatively close to the player robot and otherwise return zero.
1 2 3 4 | public int takeControl() { if (ir.getSensorValue(3) > 160) return 200; return 0; } |
As the robot moves slowly during its idle behavior we wanted it to look like it got scared when it saw the player robot and thus made it back off a random distance fast when it sees the player followed by turning either left or right which can be seen in the code below.
1 2 3 4 5 6 7 8 9 10 11 12 13 | public void action() { suppressed = false; AutAnimal.fastRotation(); AutAnimal.fastTravel(); int turn = Math.random() > 0.5 ? -1 : 1; int angle = 100 + random.nextInt(60); AutAnimal.pilot.travel(-(20+random.nextInt(30)), true); while (!suppressed && AutAnimal.pilot.isMoving()) Thread.yield(); AutAnimal.pilot.rotate(-turn * angle, true); while (!suppressed && AutAnimal.pilot.isMoving()) Thread.yield(); AutAnimal.slowRotation(); AutAnimal.slowTravel(); } |
Backlog
As was mentioned we were unfortunately not able to reach a usable solution to adding the camera feed into the controller application and decided not to spend any more time on trying to solve it for the time being. We would like to return to this problem at a later stage if we have the time to do so.
We have started implementing the behaviors and will continue working on them next time.
Finally, if we decide that we really want to use the arrow keys on the keyboard to control robot we might need to get a hold on a mechanical keyboard.
References
[1] http://www.braille2000.com/brl2000/KeyboardReq.htm
[2] http://en.wikipedia.org/wiki/Rollover_%28key%29
[3] http://code.google.com/p/vlcj/
[4] http://www.videolan.org/vlc/
[5] http://ip-webcam.appspot.com/
[6] http://code.google.com/p/spydroid-ipcamera/
[7] Lesson 10, http://bech.in/?p=362
[8] Thiemo Krink (in prep.), Motivation Networks – A Biological Model for Autonomous Agent Control
[9] End-course project 1, http://bech.in/?p=427
Pingback: End-course project 6 | Bech