95 lines
3.4 KiB
C
95 lines
3.4 KiB
C
/*
|
|
* communication.h
|
|
*
|
|
* Created: 10/03/2021 13:07:51
|
|
* Author: Nick-XMG
|
|
*/
|
|
|
|
|
|
#ifndef COMMUNICATION_H_
|
|
#define COMMUNICATION_H_
|
|
|
|
#include "ethercat_e54.h"
|
|
|
|
//Write To Ecat Total Bytes (38 bytes)
|
|
//write (2 Bytes)
|
|
volatile uint8_t *status =&ram_buffer[ram_wr_start];
|
|
volatile uint8_t *state =(((uint8_t *)&ram_buffer[ram_wr_start])+1);
|
|
//Joint (10 Bytes)
|
|
volatile int16_t *joint_rel_position =&ram_buffer[ram_wr_start+1];
|
|
volatile int16_t *joint_revolution =&ram_buffer[ram_wr_start+2];
|
|
volatile int16_t *joint_abs_position =&ram_buffer[ram_wr_start+3];
|
|
volatile int16_t *joint_speed =&ram_buffer[ram_wr_start+4];
|
|
volatile int16_t *joint_torque =&ram_buffer[ram_wr_start+5];
|
|
// Motor (20+1+1+4) = 26
|
|
volatile int16_t *motor_rel_revolutions=&ram_buffer[ram_wr_start+6];
|
|
volatile int16_t *motor_rel_position =&ram_buffer[ram_wr_start+7];
|
|
volatile int16_t *motor_abs_position =&ram_buffer[ram_wr_start+8];
|
|
volatile int16_t *motor_dutyCycle =&ram_buffer[ram_wr_start+9];
|
|
volatile int16_t *motor_speed =&ram_buffer[ram_wr_start+10];
|
|
volatile int16_t *motor_torque =&ram_buffer[ram_wr_start+11];
|
|
volatile int16_t *motor_currentPHA =&ram_buffer[ram_wr_start+12];
|
|
volatile int16_t *motor_currentPHB =&ram_buffer[ram_wr_start+13];
|
|
volatile int16_t *motor_currentPHC =&ram_buffer[ram_wr_start+14];
|
|
volatile int16_t *motor_currentBUS =&ram_buffer[ram_wr_start+15];
|
|
volatile uint8_t *hall_state =&ram_buffer[ram_wr_start+16];
|
|
volatile uint8_t *Spare_byte1 =(((uint8_t *)&ram_buffer[ram_wr_start+16])+1);
|
|
volatile int16_t *Spare_1 =&ram_buffer[ram_wr_start+17];
|
|
volatile int16_t *Spare_2 =&ram_buffer[ram_wr_start+18];
|
|
|
|
//Read From Ecat Total (35 Bytes)
|
|
// (1 Byte)
|
|
volatile uint8_t *control_mode =&ram_buffer[ram_rd_start];
|
|
volatile uint8_t *control_set =(((uint8_t *)&ram_buffer[ram_rd_start])+1);
|
|
// (34 Byte)
|
|
volatile int16_t *desired_position =&ram_buffer[ram_rd_start+1];
|
|
volatile int16_t *desired_speed =&ram_buffer[ram_rd_start+2];
|
|
volatile int16_t *desired_torque =&ram_buffer[ram_rd_start+3];
|
|
volatile int16_t *i_kp =&ram_buffer[ram_rd_start+4];
|
|
volatile int16_t *i_ki =&ram_buffer[ram_rd_start+5];
|
|
volatile int16_t *v_kp =&ram_buffer[ram_rd_start+6];
|
|
volatile int16_t *v_kd =&ram_buffer[ram_rd_start+7];
|
|
volatile int16_t *p_kp =&ram_buffer[ram_rd_start+8];
|
|
volatile int16_t *p_ki =&ram_buffer[ram_rd_start+9];
|
|
volatile uint16_t *ReductionRatio =&ram_buffer[ram_rd_start+10];
|
|
volatile int16_t *max_torque =&ram_buffer[ram_rd_start+11];
|
|
volatile int16_t *max_current =&ram_buffer[ram_rd_start+12];
|
|
volatile int16_t *max_velocity =&ram_buffer[ram_rd_start+13];
|
|
volatile int16_t *spare1 =&ram_buffer[ram_rd_start+14];
|
|
volatile int16_t *spare2 =&ram_buffer[ram_rd_start+15];
|
|
volatile int16_t *spare3 =&ram_buffer[ram_rd_start+16];
|
|
volatile int16_t *spare4 =&ram_buffer[ram_rd_start+17];
|
|
|
|
void comms_check(void)
|
|
{
|
|
*status = 1;
|
|
*state = 0;
|
|
*joint_rel_position = 3;
|
|
*joint_revolution = 4;
|
|
*joint_abs_position = 5;
|
|
*joint_speed = 6;
|
|
*joint_torque = 7;
|
|
*motor_rel_revolutions = 8;
|
|
*motor_rel_position = 9;
|
|
*motor_abs_position = 10;
|
|
*motor_dutyCycle = 11;
|
|
*motor_speed = 12;
|
|
*motor_torque = 13;
|
|
*motor_currentPHA = 14;
|
|
*motor_currentPHB = 15;
|
|
*motor_currentPHC = 16;
|
|
*motor_currentBUS = 17;
|
|
*hall_state = 18;
|
|
*Spare_byte1 = 19;
|
|
*Spare_1 = 20;
|
|
*Spare_2 = 21;
|
|
}
|
|
|
|
void clear_comms_buffer(void)
|
|
{
|
|
memset(ram_buffer, 0, ram_rd_start);
|
|
}
|
|
|
|
|
|
|
|
#endif /* COMMUNICATION_H_ */ |