# シミュレータ上のラズパイマウスを動かす方法 Part4

## ラズパイマウスを動かすまでの流れ

1. [距離センサの値の読み取り方](/project/tutorial/how_to_control_raspimouse_on_sim_1.md)
2. [モータを動かし方](/project/tutorial/how_to_control_raspimouse_on_sim_2.md)
3. [キーボードを用いたラズパイマウスの動かし方](/project/tutorial/how_to_control_raspimouse_on_sim_3.md)
4. [コントローラを用いたラズパイマウスの動かし方](/project/tutorial/how_to_control_raspimouse_on_sim_4.md) ←今ここ
5. [距離センサの値を利用したラズパイマウスの動かし方](/project/tutorial/how_to_control_raspimouse_on_sim_5.md)
6. [測域センサ(URG)を用いたSLAMの行い方](/project/tutorial/how_to_control_raspimouse_on_sim_6.md)

Part4ではコントローラを用いてシミュレータ上のラズパイマウスを動かしましょう。

コントローラを用いることにより、キーボードで操作するより自由に操作することができます。

## 前準備

コントローラで動かすために、[Ryo Okazaki](https://github.com/zaki0929)さんの[`raspimouse_game_controller`](https://github.com/zaki0929/raspimouse_game_controller)を使用します。

```
git clone https://github.com/zaki0929/raspimouse_game_controller.git
cd ~/catkin_ws
catkin_make
```

次にコントローラを扱うために必要な`joy_node`をインストールします。すでに`joy_node`をインストールしている場合、この操作を行う必要はありません。

```
sudo apt install ros-kinetic-joy
```

以上で準備完了です。

## コントローラでラズパイマウスを動かす

今回は**Logicool Wireless Gamepad F710**を使用します。

詳しくは[`raspimouse_game_controller`](https://github.com/zaki0929/raspimouse_game_controller)の[README](https://github.com/zaki0929/raspimouse_game_controller/blob/master/README.md)をご覧下さい。

まず、前回と同様に[Raspberry Pi Mouse Simulatorの動作確認](/project/setup/how_to_use_raspimouse_sim.md)に従い、Gazeboを起動します。

別のターミナルで、以下のコマンドを実行します。

このコマンドがコントローラでラズパイマウスを動かすときに使用するコマンドです。実行すると自動的にモータが通電します。

```
roslaunch raspimouse_gamepad_control run_with_base_nodes.launch
```

次に、コントローラの上のスイッチが**D**の方にセットされ、MODEのランプが**付いている**ことを確認します。

![](/files/-LRBXHNvfWHh9ONhUnFQ)

操作するときは**X**を押しながら、左の**十字キー**を押します。&#x20;

![](/files/-LR5kwpRwRMOuLjn7Dmo)

## コントローラを使用している様子：

![](/files/-LRBXHNx-EGKepyUBk1C)

## Trubleshooting

### joy\_nodeについてのエラー

```
[ERROR] [1526893382.851884948]: Couldn't open joystick /dev/input/js0. Will retry every second.
```

上記のエラーが出て、コントローラが反応しないことがあります。

コントローラを接続し直してみて下さい。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://raspimouse-sim-tutorial.gitbook.io/project/tutorial/how_to_control_raspimouse_on_sim_4.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
