I'm working on a robotics project where I have 3 services running. I have my sensor DAQ, my logic ISR (motor controller at 20kHz) and my EtherCAT slave controller.
DAQ and EtherCAT run in the idle and the logic runs during an interrupt. The logic does some calculations and controls the motor. The EtherCAT service (kinda like CANbus) runs together with my DAQ in the idle loop. I can not run the DAQ in the interrupt because that leaves me with less than 100ns for the EtherCAT service to run.
I'm not sure whether this is the right way to do this especially considering all the scary things i've read regarding data corruption when using interrupts.
Does anyone have some nice ideas on how to handle these services?
I'm running all my code on a Zynq 7020 (on the ARM Cortex) and it's written in C++.
Here is an example of my code:
/**
* Get all sensor data
*/
void Supervisor::communication(void) {
// Get all the sensors data
dispatchComm.getData(&motorAngle, &motorVelocity, &jointAngle, &springAngle, &tuningParameter);
}
/**
* Run all the logic
*/
void Supervisor::logic(void) {
dispatchLogic.calculate(tuningParameter, motorAngle, motorVelocity, jointAngle, springAngle);
dispatchLogic.getData(&angle, &magnitude);
// Dispatch values to the motor drive
dispatchComm.setMotorDriveSetpoint(angle, magnitude);
dispatchComm.writeToPiggyback((uint32_t) (tuningParameter), motorAngle, motorVelocity);
}