0

我开始在 IntelliJ IDEA 中编写NAO机器人,我在这两个方面都是新手,我创建了一些使NAO移动或说话的功能,每次看到发生了什么我都必须运行项目。现在我想在 KeyPress 上执行一些功能。你能给我举个例子吗。

如何更改此代码,以允许NAO站立、蹲伏或坐在某些按键上(例如:q-> Stand、w-> Crouch、e-> Sit)

 package test;

 import com.aldebaran.qi.Application;
 import com.aldebaran.qi.helper.proxies.ALMotion;
 import com.aldebaran.qi.helper.proxies.ALRobotPosture;
 import com.aldebaran.qi.helper.proxies.ALTextToSpeech;

 public class StandNao {

     private static ALMotion motion;

     public static void main(String[] args) throws Exception {
         Application application = new NaoSettings().NaoConnect(args);



         application.start();
         motion = new ALMotion(application.session());
         // Create an ALTextToSpeech object and link it to your current session
         ALTextToSpeech tts = new ALTextToSpeech(application.session());
         // Make your robot say something
         tts.say("MAC Start Stand");
         motion.killAll();
         ALRobotPosture posture = new ALRobotPosture(application.session());
         posture.getPostureList();
         posture.goToPosture("Stand", 1.0f);

                 Thread.sleep(10000);

         posture.goToPosture("Crouch", 1.0f);

                 Thread.sleep(10000);

         posture.goToPosture("Sit", 1.0f);
     }
 }
4

1 回答 1

2

我不会描述所有的可能性,但是为了给你一个方法,你可以查看许多 Java 库,它们可以让你管理轮询或事件驱动的键盘输入。

然后,您可以创建一个无限循环,您可以在其中聆听键盘活动,并根据击键做出反应。

它几乎不会像这样:

Keyboard.poll();
while(Keyboard.next())  {

      if(Keyboard.getEventKey() == Keyboard.KEY_LEFT && !Keyboard.getEventKeyState()) {
             // do something if the letter left arrow key is released
      }

}

还可以考虑尝试做一些有趣的事情,如果你想同时学习 Java 和 Web 方面,比如带有 REST 控制器的 Web 应用程序,当你点击网页的按钮时,你的机器人会相应地移动。

使用Java Spring Boot可以快速实现。

于 2016-04-08T13:14:41.087 回答