Pages: [1]   Go Down
Author Topic: Servo Delay when using Simulink with Ardupilot Mega and Xbee  (Read 2743 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
  Serial.begin(9600);
  myservo.attach(44); //attach servo object to pin 44 (i.e. OUT1)
}
void loop()
{
  if (Serial3.available() > 0)
  {
    ElevDefl = Serial3.read();
    Serial.println(ElevDefl);
    myservo.write(ElevDefl);
   }
}


Any help will be very much appreciated.


* VerySimpleModelPic.bmp (1062.37 KB, 803x451 - viewed 106 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi did you get this working?
Logged

Japan
Offline Offline
Jr. Member
**
Karma: 16
Posts: 79
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: