Hobbyist Toolkit

cancel
Showing results for 
Search instead for 
Did you mean: 

LINX Custom Command Error

Hello,

 

I made a custom command to control one stepper motor (one for the moment) ans use an arduino library.

 

When I run the custom command I got this error code (I've tried the example custom command everithing works well)  :

 

Error 5001 occurred at :

Custom Command.vi >>
Send Command.vi

Possible reason(s):

A timeout occured while waiting for the Arduino Mega 2560

 

The strange thing is the motor move but doesn't stop, it should go to position 8000 and then go back to position 0 ... And I get this above error to.

 

This is the firmware I've made :

 

/****************************************************************************************
** This is example LINX firmware for use with the Arduino Mega 2560 with the serial
** interface enabled.
**
** For more information see: www.labviewmakerhub.com/linx
** For support visit the forums at: www.labviewmakerhub.com/forums/linx
**
** Written By Sam Kristoff
**
** BSD2 License.
****************************************************************************************/

//Include All Peripheral Libraries Used By LINX
#include <SPI.h>
#include <Wire.h>
#include <EEPROM.h>
#include <Servo.h>
#include <AccelStepper.h>

//Include Device Sepcific Header From Sketch>>Import Library (In This Case LinxArduinoMega2560.h)
//Also Include Desired LINX Listener From Sketch>>Import Library (In This Case LinxSerialListener.h)
#include <LinxArduinoMega2560.h>
#include <LinxSerialListener.h>

//Create A Pointer To The LINX Device Object We Instantiate In Setup()
LinxArduinoMega2560* LinxDevice;
int clp();
//Initialize LINX Device And Listener
void setup()
{
//Instantiate The LINX Device
LinxDevice = new LinxArduinoMega2560();

//The LINX Listener Is Pre Instantiated, Call Start And Pass A Pointer To The LINX Device And The UART Channel To Listen On
LinxSerialConnection.Start(LinxDevice, 0);
LinxSerialConnection.AttachCustomCommand(0, clp);
}

void loop()
{
//Listen For New Packets From LabVIEW
LinxSerialConnection.CheckForCommands();

//Your Code Here, But It will Slow Down The Connection With LabVIEW
}

int clp(unsigned char numInputBytes, unsigned char* input, unsigned char* numResponseBytes, unsigned char* response)
{
#define dirPin 26
#define stepPin 25
#define motorInterfaceType 1

AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);


// Set the maximum speed and acceleration:
stepper.setMaxSpeed(1000);
stepper.setAcceleration(500);


// Set the target position:
stepper.moveTo(8000);
// Run to target position with set speed and acceleration/deceleration:
stepper.runToPosition();
delay(1000);
// Move back to zero:
stepper.moveTo(0);
stepper.runToPosition();
delay(1000);

response[0]=0;
*numResponseBytes = 1;
return 0;
}

0 Kudos
Message 1 of 7
(2,153 Views)

Hello Stargo,

 

i am not able to test your code right now, but looking at your function clp() you are using delay() functions. 

i'd guess that this delay() is causing your timeout error.

 

i suggest you to try using millis(), comparing time, and working your code around this way.

 

Let me know if it works, i'll eventually try when i'm back at the lab.

Jorge Augusto Pessatto Mondadori, PhD
Sistema Fiep
CLAD, CLD
0 Kudos
Message 2 of 7
(2,146 Views)

Thanks for your answer, I made some try.

 

Without the delay I got the same isue.

I think this line code acts like a delay : "stepper.runToPosition();"

 

 

I try a test with a move of 1 (stepper.moveTo(1);), and I don't have any problem.

 

I've try with a biger move (stepper.moveTo(10000);) and a timeout of 1000ms on the customcommand.vi and everithing work well. But if I need a move that need 10s, I need to put a 10s timout. It's not great...

 

0 Kudos
Message 3 of 7
(2,119 Views)

oh i see, it is because stepper.moveTo() in fact is a blocking function as well as delay. 

let me understand a bit more about your application:

Do you need responsiveness in software or hardware/firmware?

 

if it is software, i'd recommend using custom command only to send variable data and managing stepper control outside custom command.

if it is a hardware thing, then this library is not suited for your application. 

 

the user SINC posted a video onthe forum that creates a simple stepper command in LabVIEW, maybe that can help you.

https://youtu.be/qwvP2AzoB_M



for further help, please share your labview code as well a description of your needs and requisites.

Jorge Augusto Pessatto Mondadori, PhD
Sistema Fiep
CLAD, CLD
0 Kudos
Message 4 of 7
(2,068 Views)

I want a responsive software, I just need to move two stepper motors in same time in my project.

My other motors and actuator will work in sequence mode (one motor and then an other one ...). So I don't worry about it.

 

I did exactly what you said, in my custom command I just configure the number of steps to move and outside I manage the control of the steppers.

 

Here my code (I just have to add a condition to stepper_M1.run(); and stepper_M2.run() to avoid the run of this command when I don't need it.

 

Thanks for your help.

 

void loop()
{
//Listen For New Packets From LabVIEW
LinxSerialConnection.CheckForCommands();

stepper_M1.run();
stepper_M2.run();
}

 

int Motor_1(unsigned char numInputBytes, unsigned char* input, unsigned char* numResponseBytes, unsigned char* response)
{
//Convertion the input to unsigned interger (Step to move)
unsigned int Step_To_Move_1 = atoi(input);

// Set the maximum speed and acceleration:
stepper_M1.setMaxSpeed(15000);
stepper_M1.setAcceleration(5000);

// Set the target position:
stepper_M1.moveTo(Step_To_Move_1);
return 0;
}

 

int Motor_2(unsigned char numInputBytes, unsigned char* input, unsigned char* numResponseBytes, unsigned char* response)
{
unsigned int Step_To_Move_2 = atoi(input);
digitalWrite(Enable, LOW);
// Set the maximum speed and acceleration:
stepper_M2.setMaxSpeed(15000);
stepper_M2.setAcceleration(5000);

// Set the target position:
stepper_M2.moveTo(Step_To_Move_2);

return 0;
}

0 Kudos
Message 5 of 7
(2,042 Views)

Glad to help.

 

Since you need a responsive software, keep in mind 2 possible architectures event based: State Machine and Producer Consumer.

 

Send us a video of your completed application afterwards!

Jorge Augusto Pessatto Mondadori, PhD
Sistema Fiep
CLAD, CLD
0 Kudos
Message 6 of 7
(2,010 Views)

Yes, I was thinking to make a QMH for this application.

 

It is noted, I will do this when finished.

0 Kudos
Message 7 of 7
(2,007 Views)