|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
@ -35,6 +36,11 @@ struct RobotImp {
|
|
|
|
|
uint16_t pitch_ground;
|
|
|
|
|
uint16_t yaw;
|
|
|
|
|
uint16_t pitch;
|
|
|
|
|
enum {
|
|
|
|
|
TARGET_NONE,
|
|
|
|
|
TARGET_REL,
|
|
|
|
|
TARGET_ABS
|
|
|
|
|
} dirty_target;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
CONNECTING_TO_PROXY_PORT,
|
|
|
|
@ -87,6 +93,44 @@ robot_aim(Robot robot, float p, float y) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
robot_target(Robot robot, float pitch, float yaw) {
|
|
|
|
|
// Get the FOV angle of the point in radians
|
|
|
|
|
float FOV = 120 * (M_PI / 180);
|
|
|
|
|
yaw = yaw * (FOV / 2);
|
|
|
|
|
pitch = pitch * (FOV / 2);
|
|
|
|
|
|
|
|
|
|
// Convert to degrees
|
|
|
|
|
yaw = yaw * (180 / M_PI);
|
|
|
|
|
pitch = pitch * (180 / M_PI);
|
|
|
|
|
|
|
|
|
|
// Convert for Robomaster
|
|
|
|
|
robot->yaw = yaw * 10;
|
|
|
|
|
robot->pitch = -pitch * 10;
|
|
|
|
|
|
|
|
|
|
robot->dirty_target = TARGET_REL;
|
|
|
|
|
return 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
robot_target_to(Robot robot, float pitch, float yaw) {
|
|
|
|
|
// Get the FOV angle of the point in radians
|
|
|
|
|
float FOV = 120 * (M_PI / 180);
|
|
|
|
|
yaw = yaw * (FOV / 2);
|
|
|
|
|
pitch = pitch * (FOV / 2);
|
|
|
|
|
|
|
|
|
|
// Convert to degrees
|
|
|
|
|
yaw = yaw * (180 / M_PI);
|
|
|
|
|
pitch = pitch * (180 / M_PI);
|
|
|
|
|
|
|
|
|
|
// Convert for Robomaster
|
|
|
|
|
robot->yaw = yaw * 10;
|
|
|
|
|
robot->pitch = -pitch * 10;
|
|
|
|
|
|
|
|
|
|
robot->dirty_target = TARGET_ABS;
|
|
|
|
|
return 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
robot_led(Robot robot, unsigned char r, unsigned char g, unsigned char b) {
|
|
|
|
|
robot->colors[0] = r;
|
|
|
|
@ -219,6 +263,20 @@ robot_work(Robot robot) {
|
|
|
|
|
req_send(robot->client->dev_conn, &req);
|
|
|
|
|
robot->dirty_gimbal = false;
|
|
|
|
|
}
|
|
|
|
|
if(robot->dirty_target) {
|
|
|
|
|
if(robot->dirty_target == TARGET_REL)
|
|
|
|
|
gimbal_rotate (
|
|
|
|
|
&req, robot->seq++, true,
|
|
|
|
|
robot->pitch,
|
|
|
|
|
robot->yaw );
|
|
|
|
|
else if(robot->dirty_target == TARGET_ABS)
|
|
|
|
|
gimbal_rotate_to (
|
|
|
|
|
&req, robot->seq++, true,
|
|
|
|
|
robot->pitch,
|
|
|
|
|
robot->yaw );
|
|
|
|
|
req_send(robot->client->dev_conn, &req);
|
|
|
|
|
robot->dirty_target = TARGET_NONE;
|
|
|
|
|
}
|
|
|
|
|
if(robot->dirty_colors) {
|
|
|
|
|
set_system_led (
|
|
|
|
|
&req, robot->seq++, false,
|
|
|
|
|