所以我刚刚为雇主启动了一个项目。他们想要的东西之一是一个在 Python 上运行的机器人,并且可以通过互联网连接和笔记本电脑从任何地方进行控制。他们在我之前雇佣了另一个人,说服公司购买 DJI Robomaster EP 核心这个。 该机器人在 robomasters 应用程序中进行编程,您可以从他们的网站下载。现在我需要做的一件事是让使用 pycharm 来对机器人进行编码成为可能。到目前为止我还无法做到这一点。 其次,我需要通过给机器人一个 X 和 Y 坐标(必须在远处工作)来让机器人移动。我已经能够获得一种用于移动到 X,Y 的代码和另一个将其返回到起始位置(X=0,Y=0)的函数,但我还没有测试过,因为我需要计算想用pycharm来给机器人编程。代码的第二个问题是它需要驱动的区域是U形的,并且它不能击中中间的物体,因为它非常昂贵。
atm 代码:
import time
from dji_robomaster_sdk import RoboMaster
from dji_robomaster_sdk import robot
from dji_robomaster_sdk import armor
from dji_robomaster_sdk import chassis
# Initialize the robot
robo = RoboMaster()
robo.initialize()
# Define the starting position
starting_position = (0, 0)
# Define the U-shaped area
area_width = 100
area_height = 50
# Function to make the robot go back to the starting position
def go_to_starting_position():
global starting_position
chassis.move(0, 0, 0, 0).wait_for_completed()
chassis.move(-starting_position[0], 0, 0, 0).wait_for_completed()
chassis.move(0, 0, 0, 0).wait_for_completed()
# Function to check if the given coordinates are within the U-shaped area
def is_within_area(x, y):
global area_width, area_height
return -area_width / 2 <= x <= area_width / 2 and -area_height / 2 <= y <= area_height / 2
# Function to make the robot go to the given coordinates
def go_to_coordinates(x, y):
global starting_position
if not is_within_area(x, y):
print("The given coordinates are outside the U-shaped area.")
return
if x < 0:
x = 0
if y < 0:
y = 0
if x > area_width:
x = area_width
if y > area_height:
y = area_height
chassis.move(x - starting_position[0], y - starting_position[1], 0, 0).wait_for_completed()
starting_position = (x, y)
# Example usage
go_to_coordinates(50, 0)
time.sleep(2)
go_to_coordinates(0, 25)
time.sleep(2)
go_to_coordinates(-50, 0)
time.sleep(2)
go_to_coordinates(0, -25)
time.sleep(2)
go_to_starting_position()
# Shut down the robot
robo.close()
我不是程序员,所以我什至不知道上面的代码是否正确。 感谢所有帮助!