Go Down

Topic: Servo Delay when using Simulink with Ardupilot Mega and Xbee (Read 4260 times) previous topic - next topic


Hi guys. I'm trying to control my servos that are connected to the Arduino mega using Simulink via Xbee modules.

The problem is that there is a huge delay between the physical servo rotation and the instructions pushed out from simulink. I've used a scope block in Simulink to track the instruction being sent to the Serial Block and can visually see the delay in servo response vs the signal being sent out.

Attached is my extremely simple Simulink Model to test the servo response.

And here's my code that I upload to Arduino board:

//This script works with SysIDModel.mdl
//The script simply reads the serial data received as the elevator
//deflection and pass it to the 'myservo' object.

#include <Servo.h>
Servo myservo; //create servo object
int ElevDefl; //variable to store servo rotation angle

void setup()
  Serial3.begin(38400); // initialize serial ports 0 & 3
  myservo.attach(44); //attach servo object to pin 44 (i.e. OUT1)
void loop()
  if (Serial3.available() > 0)
    ElevDefl = Serial3.read();

Any help will be very much appreciated.


Hi I'm intersted in using Simulink to rotate a servo.
I wan't know the detail of the "Pulse Generattor"  in the model.


Your issue is that you're not using the accelerator. You need to choose the option "Accelerator" or "Rapid Accelerator"

Go Up