RoboMaster S1にpythonでプレーンテキストプロトコルを送信する
現状
最近RoboMasterS1を知人からもらいました。
多くある機能はとても魅力的で使用範囲はとても広いと感動しました。
また、アプリも使いやすく完成度の高さに驚かされています。
自分はS1の機能を活用してバトル以外のことで活用したいと思いました。
その際にPythonのプログラムで一貫して管理する必要が出てきます。
そうするとS1をデフォルトアプリ以外から操作した方が何かと都合が良さそうなので、
デフォルトのアプリを使わない方法でS1をプログラムしようと考えました。
開発者モードがあり公式サイトを参考して進めていこうと思っています。
問題
このサイトに従って進めていたのですが、「接続スクリプトの設定」で問題が出ました。
S1のWi-Fi下に入り
import socket
import sys
host = "192.168.2.1"
port = 40923
def main():
address = (host, int(port))
# Establish a TCP connection with the robot's control command port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("Connecting...")
s.connect(address)
print("Connected!")
while True:
# Wait for the user to input a control command
msg = input(">>> please input SDK cmd: ")
# Exit the current program when the user enters Q or q
if msg.upper() == 'Q':
break
# Add a ';' terminator to the end
msg += ';'
# Transmit the control command to the robot
s.send(msg.encode('utf-8'))
try:
# Wait for the robot to return the execution result
buf = s.recv(1024)
print(buf.decode('utf-8'))
except socket.error as e:
print("Error receiving :", e)
sys.exit(1)
if not len(buf):
break
# Disable the port connection
s.shutdown(socket.SHUT_WR)
s.close()
if __name__ == '__main__':
main()
を実行しました。普通ならこれでConnected!
と出るみたいなのですが、自分の場合は
Connecting...
Traceback (most recent call last):
File "rm_direct_connection_sdk.py", line 53, in <module>
main()
File "rm_direct_connection_sdk.py", line 18, in main
s.connect(address)
ConnectionRefusedError: [Errno 61] Connection refused
のようなエラーが出てきます。
どうしたら正常に動作してConnected!
が出てくるようになりますか?
取り組んだこと
Errno:61
をネットで調べるとサーバー側に問題がある際に出てくるエラーだそうです。
なので、S1の電源を入れ直したりしてみました。
0 likes