Fcns
Fcns
Fcns
#define RXD2 16
#define TXD2 17
// UART FOR HMI
#define RXD1 4
#define TXD1 2
// HAND WHEEL PULSE ENCODER
#define CLK_ENCODER 27
#define DT_ENCODER 25
// HOME SENSOR
#define HOME_SENSOR_J1 21 // 39
#define HOME_SENSOR_J2 22 // 36
#define HOME_SENSOR_J3 34 // 35
#define HOME_SENSOR_J4 35 // 34
#define HOME_SENSOR_J5 36 // 22
#define HOME_SENSOR_J6 39 // 21
// BUZZER
#define BUZZER 5
// RELAY
#define RELAY_5 32
#define RELAY_6 33
// BUTTON TEACH PENDANT
#define RED_BUTTON 15
#define GREEN_BUTTON 26
// VSPI FOR ETHERNET MODULE AND SD CARD
#define REASSIGN_PINS
int sck = 18;
int miso = 19;
int mosi = 23;
int cs = 14; // Chip Select Pin for SD CARD
int cs_ethernet = 13; // Chip Select Pin for ETHERNET W5500
// NO USE
// #define RELAY_1 13
// #define RELAY_2 18
// #define RELAY_3 19
// #define RELAY_4 23
// #define SW_ENCODER
//===========================================================================
// DEFINE SERVO ID
//===========================================================================
#define ID_1 1
#define ID_2 2
#define ID_3 3
#define ID_4 4
#define ID_5 5
#define ID_6 6
//===========================================================================
// DEFINE STATE
//===========================================================================
#define ON_SERVO 1
#define OFF_SERVO 0
#define DELAY_TICK_ENABLE_SERVO 100
#define DELAY_TICK_DISABLE_SERVO 100
#define ACCELERATION_TIME_PARAMETER 3
#define DECELERATION_TIME_PARAMETER 4
#define NULL_POS -1
#define RETURN_OK 0
#define CW 1
#define CCW 0
//===========================================================================
// DEFINE TCP STASK
//===========================================================================
#define TCP_TASK_POS_1 1
#define TCP_TASK_POS_2 2
#define TCP_TASK_POS_3 3
#define TCP_TASK_POS_4 4
#define TCP_TASK_POS_5 5
#define TCP_TASK_POS_6 6
#define TCP_TASK_POS_TG_1 7
#define TCP_TASK_POS_TG_2 8
#define TCP_TASK_HOME 9
#define TCP_TASK_CALIB 10
#define TCP_TASK_WAKEUP 11
#define TCP_TASK_SLEEP 12
#define TCP_TASK_ON_SERVO 13
#define TCP_TASK_OFF_SERVO 14
#define TCP_TASK_STOP 15
//===========================================================================
// DEFINE HARDWARE_SERIAL
//===========================================================================
HardwareSerial HMI(1);;
//===========================================================================
// DEFINE VARIABLES
//===========================================================================
struct StructRow
{
unsigned int Mark_Array[101] = {};
unsigned int rowNo;
String posName;
float EEx_Value;
float EEy_Value;
float EEz_Value;
String EE_Orientation;
unsigned int moveTimeValue;
unsigned int waitTimeValue;
String out1State;
String out2State;
struct EEC_R06
{
float r11, r12, r13;
float r21, r22, r23;
float r31, r32, r33;
} EEC_R06_Matrix;
};
StructRow Row_Data_T1;
StructRow Row_Data_T2;
StructRow Row_Data_T3;
struct Struct_Fixed_Modes
{
struct Home_Mode
{
// HOME THETA
const int Theta1 = 0, Theta2 = 155, Theta3 = -65, Theta4 = 0, Theta5 = -60,
Theta6 = 0;
} Home;
struct Wakeup_Mode
{
// WAKE UP THETA
const int Theta1 = 0, Theta2 = 90, Theta3 = 0, Theta4 = 0, Theta5 = -90,
Theta6 = 0;
} Wakeup;
struct Sleep_Mode
{
// SLEEP THETA
const int Theta1 = 0, Theta2 = 123, Theta3 = -33, Theta4 = 0, Theta5 = -90,
Theta6 = 0;
} Sleep;
} Fixed_Modes;
// FOR KINEMATICS
float d0 = 228,
L1 = 55, L2 = 330, L3 = 62, d1 = 330, d2 = 201;
float POS = 90, NEG = -90;
float theta1 = 0, theta2 = 0, theta3 = 0, theta4 = 0, theta5 = 0, theta6 = 0;
float theta1_old = 0, theta2_old = 0, theta3_old = 0, theta4_old = 0, theta5_old =
0, theta6_old = 0;
float theta1_FK = 0, theta2_FK = 0, theta3_FK = 0, theta4_FK = 0, theta5_FK = 0,
theta6_FK = 0;
float theta1_IK = 0, theta2_IK = 0, theta3_IK = 0, theta4_IK = 0, theta5_IK = 0,
theta6_IK = 0;
float theta1_IK_T = 0, theta2_IK_1 = 0, theta2_IK_2 = 0, theta3_IK_1 = 0,
theta3_IK_2 = 0, theta5_IK_1 = 0, theta5_IK_2 = 0;
float tolerance = 2;
int Number_Of_Solutions = 0;
int i = 0;
// TEMPLATE MATRIX
template <int rows, int cols>
using MatrixSize = Eigen::Matrix<float, rows, cols>;
// OUT RELAY STATUS [Out1 5V - Out2 24V] [false: OFF | true: ON]
bool OUT1_STATUS = false;
bool OUT2_STATUS = false;
// UART FOR HMI
// const int BUFFER_SIZE = 100; // Độ dài tối đa của chuỗi
// char HMI_BUFFER[BUFFER_SIZE];
// int bufferIndex = 0;
bool newDataReceived = false;
String HMI_BUFFER_DATA = "";
String CURRENT_PAGE = "HP";
// OTHER
String Theta_Selection = "";
String Axis_Selection = "";
String EE_Selection = "";
MatrixSize<4, 4> FK_Jog;
MatrixSize<3, 3> R_0_6_Temp;
MatrixSize<3, 1> EE_Target_Matrix;
float THETA2_OFFSET = 90;
float theta1_Init = 0, theta2_Init = 0, theta3_Init = 0, theta4_Init = 0,
theta5_Init = 0, theta6_Init = 0;
float slider1_target = 0, slider2_target = 0, slider3_target = 0, slider4_target =
0, slider5_target = 0, slider6_target = 0;
bool EN_READY = false;
bool DONE_ALM = false;
bool FIND_NEAREST_SOLUTION = false;
float Theta1_IK_READY = 0, Theta2_IK_READY = 0, Theta3_IK_READY = 0,
Theta4_IK_READY = 0, Theta5_IK_READY = 0, Theta6_IK_READY = 0;
unsigned int Run_Time_Target = 10;
String IK_Result = "";
float EEx_Target = 0;
float EEy_Target = 0;
float EEz_Target = 0;
unsigned int row_begin = 1;
unsigned int Table_No = 1;
unsigned int Max_Table_No = 10;
String Table_Name = "Jog Program";
// ModbusIP object
ModbusIP Modbus;
EthernetClient client;
void Read_HMI();
void Write_End_Byte_HMI();
void Write_HMI(String page, String object, String para, String content);
void Write_HMI(String page, String object, String para, unsigned int value);
void Write_HMI(String object, String para, String content);
void Write_HMI(String object, String para, unsigned int value);
void Write_HMI_Val(String object, String para, float value);
void Alarm_HMI(String alarm_Content);
void Update_Row_Data_HMI(unsigned int row_update);
void Update_Row_Null_HMI(unsigned int row_update);
void Clear_Data_Table();
void Update_Data_HMI();
void clearBufferData();
void TCP_Led();
void LINK_Led();
void Update_Data_Table(unsigned int row_begin, unsigned int row_end);
void Mark_Row(unsigned int row_update, bool runState);
void ENABLE_ALL_SERVO();
void DISABLE_ALL_SERVO();
void CLEAR_ALL_POSITION();
float GET_THETA_1();
float GET_THETA_2();
float GET_THETA_3();
float GET_THETA_4();
float GET_THETA_5();
float GET_THETA_6();
float GET_SPEED_1();
float GET_SPEED_2();
float GET_SPEED_3();
float GET_SPEED_4();
float GET_SPEED_5();
float GET_SPEED_6();
void SET_ALL_ACCELERATION_TIME(unsigned int accel_time);
void SET_ALL_DECELERATION_TIME(unsigned int decel_time);
void RESET_ALL_ALARM();
void SAVE_ALL_PARAMETER();
void MOVE_ORIGIN_SERVO_1();
void MOVE_ORIGIN_SERVO_2();
void MOVE_ORIGIN_SERVO_3();
void MOVE_ORIGIN_SERVO_4();
void MOVE_ORIGIN_SERVO_5();
void MOVE_ORIGIN_SERVO_6();
void Joint_1_Calibration();
void Joint_2_Calibration();
void Joint_3_Calibration();
void Joint_4_Calibration();
void Joint_5_Calibration();
void Joint_6_Calibration();
void Robot_Calibration();
void Update_Home_Sensor_State();
void Update_Encoder_State();
void Update_Speed_Selection();
void Update_Slider_State();
void Update_Current_Page_Fcns();
void Update_System_Status();
void Update_Out_Relay_Status();
void Run_Robot_Position_Table();
void Run_Robot_TCP_Mode(int16_t table_target);
template <typename Fixed_Modes_Fcns>
void Move_Robot_Fixed_Modes(const Fixed_Modes_Fcns &fixed_modes, unsigned int
speed);
void Check_And_Run_Robot_IK_ENC();
void Check_And_Run_Robot_IK_SLI();
void Check_Stop_Robot_TCP_Mode();
void Run_Robot_To_Target_Base_Mode(String move_Mode);
void Move_Change_EE_Orientatation_Base_Mode_Page();
void Check_Move_Change_EE_Orientation_Base_Mode();
void Check_Change_Page_Fcns();
void Home_Page();
void Kinematic_Slider_Mode_Page();
void Kinematic_Encoder_Mode_Page();
void Select_EE_Orientation_Page();
void Base_Mode_Page();
void Position_Table_Page();
void TCPIP_Mode_Page();
void Debug_Page();
void loop();