Paso 19: OpenCV: encontrar el ángulo
#Don't start moving until things are ready.if iFrame >=160: #This compares the bot's heading with the target angle. It must#be +-30 for the bot to move forward, otherwise it will turn. shortestAngle = targetDegs - intHeadingDeg if shortestAngle >180: shortestAngle -=360if shortestAngle <-180: shortestAngle +=360if shortestAngle <=30and shortestAngle >=-31: tranx =3print"Forward"elif shortestAngle >=1: tranx =2print"Turn Right"elif shortestAngle <1: tranx =4print"Turn Left" | 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
156-177: Aquí estamos tratando de encontrar el ángulo entre el robot y su destino. Básicamente dividimos toda la pantalla en cuatro cuadrantes, pero siempre utilizando centroide del robot como el punto de origen. Luego calculamos la pendiente entre X del objetivo y Y (tY, tX) y el robot X y Y (cxAvg y cyAvg).
Algo como esto:
Si el objetivo fuera que se encuentra en el cuadrante III, iría algo como esto.
Si desea cavar más lejos en las funciones trigonométricas en Python, divertirse. Compartir si encuentra matemáticas mejor :)