ESP8266 + Python Scripts Implement wireless crowd control

Setup environment

โปรดอ้างอิงคำแนะนำของ WiFi ESP8266arrow-up-right และใช้ Arduino IDEarrow-up-right เพื่อเปิดโปรแกรมตัวอย่าง (ESP8266WiFiController.ino) เพื่ออัปโหลดเฟิร์มแวร์ควบคุม WiFi สำหรับโมดูล ESP8266

Install Python3, and download the Python scriptsarrow-up-right to control the robot.

Script introduction

สำหรับ Python เวอร์ชัน 3.8 ขึ้นไป มีการเปลี่ยนแปลง Syntax ในการกำหนด Type ของตัวแปร สคริปต์นี้สามารถใช้งานได้แต่ต้อง comment และ uncomment หลายคำสั่งที่เกี่ยวข้องตามรุ่นของ Python ที่คุณได้ติดตั้งไว้ ตัวอย่างเช่นสคริปต์ด้านล่างนี้รองรับ Python เวอร์ชันต่ำกว่า 3.8:

"""
In Python 3.8 and earlier, the name of the collection type is
capitalized, and the type is imported from the 'typing' module
"""
# from typing import Union, Optional             # for Python 3.9+
from typing import Union, Dict, List, Optional   # for Python 3.7

แอปสคริปต์นี้สามารถควบคุมหุ่นยนต์ได้เพียงหนึ่งตัว หรือควบคุมหลายตัวพร้อมกันได้ โดยสามารถทำได้โดยการแก้ไขคำสั่งต่อไปนี้ใน example.py:

# ip = "192.168.0.108"                     # for only one robot
ip = ["192.168.0.110", "192.168.0.108"]    # for multiple robots

How to Use

อ้างอิงถึง the instructionarrow-up-right ให้กำหนด IP address ของโมดูล ESP8266 ผ่าน WiFi และนำมาต่อกับบอร์ดหลักของหุ่นยนต์ หลังจากนั้นเมื่อเปิดเครื่องหุ่นยนต์แล้ว คุณสามารถใช้ python เพื่อรันสคริปต์ example.py เพื่อควบคุมหุ่นยนต์ได้ผ่านวิธีไร้สาย คุณสามารถปรับแต่งคำสั่งในสคริปต์ต่อไปนี้ (แก้ไขเนื้อหาของ list) ตามความต้องการจริงของคุณ เพื่อให้หุ่นยนต์ทำการแสดงพฤติกรรมต่างๆ ได้:

cmds = [
        Command.sit, Command.balance, Command.stepping, Command.pee,
        Command.stop
    ]

สำหรับคำสั่งการกระทำที่รองรับในปัจจุบันโปรดดูที่ไฟล์โค้ด actions.h(in ESP8266WiFiControllerarrow-up-right).

Last updated

Was this helpful?