TechTheTime-HighLevel 0.0.1
The high level robot's code using ros2-foxy for the robotics competition(Erobot-2022)
RobotStatus.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <const_shared/MotionConst.hpp>
4#include <action_msg_srv_shared/order_codes.hpp>
5#include <iostream>
6
7enum class Team {
8 YELLOW,
9 PURPLE,
10 NONE
11};
12
13enum class Robot {
14 MASTER,
15 SLAVE,
16 NONE
17};
18
20public:
21
22 RobotStatus() = delete;
23
24 static double x;
25 static double y;
26 static double angle_;
27 static double angle;
28 static Team team;
29 static Robot robot;
30
31
32 static void atomic_move(int64_t left_ticks, int64_t right_ticks) {
33 double dbeta = 0;
34 double cos_angle = cos(angle_);
35 double sin_angle = sin(angle_);
36 if(SIGN(left_ticks) == SIGN(right_ticks)) {
37 double c_ticks = SIGN(left_ticks) * MIN(ABS(left_ticks), ABS(right_ticks));
38 double dl = c_ticks * TICKS_TO_MM;
39 x += (dl * cos_angle);
40 y += (dl * sin_angle);
41 dbeta = (robot == Robot::MASTER ? TICKS_TO_RADIANS_MASTER : TICKS_TO_RADIANS_SLAVE) * (left_ticks - right_ticks);
42 } else if(left_ticks < 0 && right_ticks >= 0) {
43 double alpha = MIN(ABS(left_ticks), ABS(right_ticks)) * (robot == Robot::MASTER ? TICKS_TO_RADIANS_HALF_BASE_MASTER : TICKS_TO_RADIANS_HALF_BASE_SLAVE);
44 angle_ -= alpha;
45 dbeta = -(robot == Robot::MASTER ? TICKS_TO_RADIANS_MASTER : TICKS_TO_RADIANS_SLAVE) * ABS(ABS(left_ticks) - ABS(right_ticks));
46 } else if(left_ticks >= 0 && right_ticks < 0) {
47 double alpha = MIN(ABS(left_ticks), ABS(right_ticks)) * (robot == Robot::MASTER ? TICKS_TO_RADIANS_HALF_BASE_MASTER : TICKS_TO_RADIANS_HALF_BASE_SLAVE);
48 angle_ += alpha;
49 dbeta = (robot == Robot::MASTER ? TICKS_TO_RADIANS_MASTER : TICKS_TO_RADIANS_SLAVE) * ABS(ABS(left_ticks) - ABS(right_ticks));
50 }
51 angle_ += dbeta;
52 double dr = dbeta * (robot == Robot::MASTER ? WHEEL_DISTANCE_MASTER / 2 : WHEEL_DISTANCE_SLAVE / 2);
53 x += dr * (1 - dbeta * dbeta / 2);
54 y += dr * dbeta;
55 double theta = ABS(angle_) - 2 * M_PI * ((int) (ABS(angle_) / (2 * M_PI)));
56 angle = (angle_ < 0) ? (2*M_PI - theta) : theta;
57 }
58};
Robot
Definition: RobotStatus.hpp:13
Team
Definition: RobotStatus.hpp:7
@ YELLOW
@ PURPLE
Definition: RobotStatus.hpp:19
static Robot robot
Definition: RobotStatus.hpp:29
static Team team
Definition: RobotStatus.hpp:28
static double angle
Definition: RobotStatus.hpp:27
RobotStatus()=delete
static double y
Definition: RobotStatus.hpp:25
static double angle_
Definition: RobotStatus.hpp:26
static void atomic_move(int64_t left_ticks, int64_t right_ticks)
Definition: RobotStatus.hpp:32
static double x
Definition: RobotStatus.hpp:24