Jump to content
OMRON Forums

how to stop c program user-defined servo algorithm in the realtime routines folder on IDE?


Recommended Posts

Posted (edited)

We have constructed a user-defined servo C program algorithm in the realtime routines folder. After build and downloaded and enabled a motor using ( #nj/ ) command from terminal where n is the motor number, the servo algorithm starts running. However, I do not know how to stop the algorithm afterwards and it keeps running forever. I know how to stop the motor or how to kill the amplifier, but no idea about the algorithm itself. Any comment would be appreciated.

Edited by moha_sa
Posted

The servo algorithm is started by setting Motor[x].ServoCtrl=1. I would not recommend stopping this by setting the value to 0, as encoder position would no longer be tracked.

If you want to stop some function of your user servo routine when the motor is not in closed loop or amplifier enabled, I would suggest  an if statement looking at Mptr->ClosedLoop or Mptr->AmpEna.

Is this servo algorithm attached to a physical motor with an encoder?

Posted (edited)

Thank you very much Eric. The answer is Yes or no. For now we just use a motor#n address which is not connected to any physical motor to be safe.

Our goal is to call the user-defined servo routine from a c program on the IDE. I tried out your flag check idea (Mptr->ClosedLoop or Mptr->AmpEna), but still after enabling motor  ( #nj/ from terminal the sevoCtrl routine starts and never gets stop; I actually confirmed that by printing a command on the unsolicited window from the servoCtrl function below. I am still looking for a stop command such that I can call it from terminal and be able to stop servoCtrl routine below, in other words what is the opposite command to (#nj/) .  Any idea would be greatly appreciated.

double PIDmodel_user_servo(struct MotorData *Mptr)
{
   servoout = 0;

    //In this loop it is asked to stop sending message to unsolicited window once motor amplifier was disabled

// Motor[n].ServoCtrl = 0 from terminal, but it does not seem to work as it keeps printing the message on the unsolicited //window forever until we reset the whole system.

  if (Mptr->AmpEna)
  {
     servoout = 0;

    MyCharArray[0]= 'H';
    Send(1,&MyCharArray);
   }
 //use_return
  return servoout;
}

Edited by moha_sa
Posted

You can disable the servo algorithm by setting Motor[x].ServoCtrl=0. While this may be okay for auxiliary functions written in custom C functions, It is strongly discouraged for motors. This setting would prevent encoder tracking and safety checks.

A better solution would be for the servo routine to behave differently when the motor not in closed loop. Our simple servo routine example returns 0 servo effort in this case.
 

double MyServo(struct MotorData *Mptr)
{
	double ServoEffort;

	if (Mptr->ClosedLoop && Mptr->AmpEna)
	{
		ServoEffort = Mptr->Servo.Kp * Mptr->PosError - Mptr->Servo.Kvfb * Mptr->ActVel;
		Mptr->Servo.Integrator += Mptr->PosError * Mptr->Servo.Ki;
		ServoEffort += Mptr->Servo.Integrator;
		return ServoEffort;
	}
	else
	{
		Mptr->Servo.Integrator = 0.0;
		return 0;
	}
}

 

  • Like 1
  • 2 years later...
Posted

I would like to ask about the user-defined algorithm that I also wrote in usrcode.c, but whenever I enable the motor, an error message appears indicating that the maximum following error limit has been exceeded. Can you share your algorithm source code for me to learn from?

Thanks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...