【问题标题】:So I want my robot to go to a desired coordinate on webots所以我希望我的机器人在 webbots 上到达所需的坐标
【发布时间】:2021-05-13 00:41:59
【问题描述】:

我希望我的机器人前往世界上所需的坐标。我唯一能做到的就是让机器人在每次遇到障碍物时都前进并转身,但这都是随机的,我无法让机器人去世界上我想去的地方。 有什么建议吗?

from controller import Robot, Motor, DistanceSensor, Compass
import time

robot = Robot()


timestep = int(robot.getBasicTimeStep())
MAX_SPEED = 12

distanciaLimite = 0.1 

leftMotor = robot.getDevice('left wheel motor')
rightMotor = robot.getDevice('right wheel motor')

sensorDistancias = []
nombreSensor = [
    'ps0', 'ps1', 'ps2', 'ps3',
    'ps4', 'ps5', 'ps6', 'ps7'
]

izq = True


compassXY = robot.getCompass('compassXY_01')
compassXY.enable(timestep)
compassZ = robot.getCompass('compassZ_01')
compassZ.enable(timestep)

for x in range(8):
    sensorDistancias.append(robot.getDevice(nombreSensor[x]))
    sensorDistancias[x].enable(timestep)

def foward():
   rightMotor.setVelocity(0.7 * MAX_SPEED)
   leftMotor.setVelocity(0.7 * MAX_SPEED)
   rightMotor.setPosition(float('inf'))
   leftMotor.setPosition(float('inf'))

def stop():
   rightMotor.setVelocity(0)
   leftMotor.setVelocity(0)


def turn_right():
   tiempo=0
   tiempoInicial=time.time()
   while robot.step(timestep) != -1:
       rightMotor.setVelocity(-0.5 * MAX_SPEED)
       leftMotor.setVelocity(0.5 * MAX_SPEED)
       rightMotor.setPosition(float('inf'))
       leftMotor.setPosition(float('inf'))
       lecturaSensor = []
       for i in range(8):
        lecturaSensor.append(sensorDistancias[i].getValue())   
       obstaculo = lecturaSensor[4] < distanciaLimite or lecturaSensor[5] < distanciaLimite
       if obstaculo:
           print("asdad")
       else:
           print("no esta aqui")
           return
       tiempoFinal=time.time()
       tiempo=tiempoFinal-tiempoInicial
   return
   

def doblarIzquierda():
   tiempo=0
   tiempoInicial=time.time()
   while robot.step(timestep) != -1:
       leftMotor.setVelocity(-0.5 * MAX_SPEED)
       rightMotor.setVelocity(0.5 * MAX_SPEED)
       leftMotor.setPosition(float('inf'))
       rightMotor.setPosition(float('inf'))
       lecturaSensor = []
       for i in range(8):
        lecturaSensor.append(sensorDistancias[i].getValue())   
       obstaculo = lecturaSensor[2] < distanciaLimite or lecturaSensor[3] < distanciaLimite
       if obstaculo:
           print()
       else:
           return
       tiempoFinal=time.time()
       tiempo=tiempoFinal-tiempoInicial
   return
 
while robot.step(timestep) != -1:
    avanzar()
    XY = compassXY.getValues()
    Z = compassZ.getValues()
    print('compas XY',XY)
    print('compas Z',Z)
    
    
    lecturaSensor = []
    for i in range(8):
        lecturaSensor.append(sensorDistancias[i].getValue())
    #print(lecturaSensor)
    
    
    obstaculo = lecturaSensor[2] < distanciaLimite or lecturaSensor[3] < distanciaLimite
    #print(lecturaSensor[2] ," ", distanciaLimite)
    if obstaculo:
        detener()
        doblarIzquierda()

西班牙语中有一些东西,因为我说西班牙语,如果它引起混乱的话。 我正在使用 firebird6 预制的 webbots 机器人。 尝试使用指南针但没有用。请帮忙

【问题讨论】:

  • 如果您希望您的机器人避开障碍物并到达所需位置,那么它比简单的 Python 控制器要复杂得多。您需要构建地图、本地化、全局规划器和本地规划器。 Navigation2 包实现了相当强大的导航算法:github.com/ros-planning/navigation2

标签: python controller webots


【解决方案1】:

您需要 gps.h 来读取坐标。您可以先阅读文档。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2021-10-05
  • 2021-01-02
  • 1970-01-01
  • 2022-01-09
  • 2014-05-08
  • 1970-01-01
  • 2021-07-12
  • 2020-08-17
  • 1970-01-01
相关资源
最近更新 更多