Jump to content
OMRON Forums

Recommended Posts

Posted
I've written a basic user servo, using the code from the training slides. I assign the function to "user servo 1" in the IDE, then build and download all programs. There are no errors or warnings with this process. After this process, I check and UserAlgo.ServoCtrlAddr[1] = $0. I was under the impression that a new memory address would be assigned. Here is the user servo code I'm using: usrcode.h: #include #include // Global Rt/Gp Externals and structures #include double user_pid_ctrl(struct MotorData *Mptr); EXPORT_SYMBOL(user_pid_ctrl); usrcode.c: #include "usrcode.h" extern struct SHM *pshm; // Pointer to shared memory extern volatile unsigned *piom; // Pointer to I/O memory extern void *pushm; // Pointer to user memory double user_pid_ctrl(struct MotorData *Mptr) { double ctrl_effort; // control effort calculated from the algorithm if(Mptr->ClosedLoop) // if the motor is in closed loop mode (Motor[m].ClosedLoop = 1) { // Use PID gains stored in the Motor[m].Servo structure gain settings ctrl_effort = Mptr->Servo.Kp * Mptr->Servo.PosError - Mptr->Servo.Kvfb * Mptr->ActVel; //PD terms Mptr->Servo.Integrator += Mptr->PosError * Mptr->Servo.Ki; // I term ctrl_effort += Mptr->Servo.Integrator; //sum PD and I efforts return ctrl_effort; } else // when open loop { Mptr->Servo.Integrator = 0.0; //Zero integrator when in open loop return 0.0; // return zero control effort } } Any advice on what to check next? Thanks, Scott
  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Posted
Make sure usralgo.ko is in the bin/Debug folder in your PC. [quote='scott.eichhorn@etrema.com' pid='491' dateline='1278446579'] I've written a basic user servo, using the code from the training slides. I assign the function to "user servo 1" in the IDE, then build and download all programs. There are no errors or warnings with this process. After this process, I check and UserAlgo.ServoCtrlAddr[1] = $0. I was under the impression that a new memory address would be assigned. Here is the user servo code I'm using: usrcode.h: #include #include // Global Rt/Gp Externals and structures #include double user_pid_ctrl(struct MotorData *Mptr); EXPORT_SYMBOL(user_pid_ctrl); usrcode.c: #include "usrcode.h" extern struct SHM *pshm; // Pointer to shared memory extern volatile unsigned *piom; // Pointer to I/O memory extern void *pushm; // Pointer to user memory double user_pid_ctrl(struct MotorData *Mptr) { double ctrl_effort; // control effort calculated from the algorithm if(Mptr->ClosedLoop) // if the motor is in closed loop mode (Motor[m].ClosedLoop = 1) { // Use PID gains stored in the Motor[m].Servo structure gain settings ctrl_effort = Mptr->Servo.Kp * Mptr->Servo.PosError - Mptr->Servo.Kvfb * Mptr->ActVel; //PD terms Mptr->Servo.Integrator += Mptr->PosError * Mptr->Servo.Ki; // I term ctrl_effort += Mptr->Servo.Integrator; //sum PD and I efforts return ctrl_effort; } else // when open loop { Mptr->Servo.Integrator = 0.0; //Zero integrator when in open loop return 0.0; // return zero control effort } } Any advice on what to check next? Thanks, Scott [/quote]
Posted
You should never have to do that. What is the version and date of the IDE you are using. [quote='scott.eichhorn@etrema.com' pid='503' dateline='1278684197'] That fixed the problem. Will I have to copy that file every time I create a new project, or was this an unusual occurrence? Thanks, Scott [/quote]
Posted
1.1.0.97 Jan 2010. I did copy the solution and folder from my C: drive (since there's no "save as" in Visual Studio !?!) to a networked drive, if that would make a difference. I've been accessing/updating the networked version. Scott [quote='hbausley' pid='504' dateline='1278687061'] You should never have to do that. What is the version and date of the IDE you are using. [quote='scott.eichhorn@etrema.com' pid='503' dateline='1278684197'] That fixed the problem. Will I have to copy that file every time I create a new project, or was this an unusual occurrence? Thanks, Scott [/quote] [/quote]
Posted
Ok, now Motor[1].Ctrl = UserAlso.ServoCtrlAddr[1]. However, when I close the loop and command a 50 micron position change, no control effort is generated and I sit at 50 micron following error. I've previously tuned the PID gains for stable control when Motor[1].Ctrl = Sys.ServoCtrl, and these are the gains I'm using now. The usrcode.h is the same as listed in my first post. Here is the current usrcode.c: // Future versions will replace this with a narrowband control algrithom //-------------------------------------------------------------------------------- #include "usrcode.h" extern struct SHM *pshm; // Pointer to shared memory extern volatile unsigned *piom; // Pointer to I/O memory extern void *pushm; // Pointer to user memory double user_pid_ctrl(struct MotorData *Mptr) { double ctrl_effort; // control effort calculated from the algorithm pshm->Ddata[1] = 3; if(Mptr->ClosedLoop) // if the motor is in closed loop mode (Motor[m].ClosedLoop = 1) { // Use PID gains stored in the Motor[m].Servo structure gain settings ctrl_effort = Mptr->Servo.Kp * Mptr->PosError - Mptr->Servo.Kvfb * Mptr->ActVel; //PD terms Mptr->Servo.Integrator += Mptr->PosError * Mptr->Servo.Ki; // I term ctrl_effort += Mptr->Servo.Integrator; //sum PD and I efforts pshm->Ddata[1] = 1; return ctrl_effort; } else // when open loop { Mptr->Servo.Integrator = 0.0; //Zero integrator when in open loop pshm->Ddata[1] = 2; return 0.0; // return zero control effort } } I added the Ddat[1] shared memory assignments as a way to check the progress of the program. The default value is 0 and it does not change during program execution. The task manager shows Motor 1 is running and using the custom servo algorithm. Do you spot any obvious code errors or have any other areas I should check? Thanks again, Scott
  • 1 year later...
Posted
We are having a smiliar problem with our custom servo routine. UserAlgo.ServoCtrlAddr[1] = $0 and we have usralgo.ko in the bin/Debug folder on the PC. Any other reasons this would occur?
Posted
We deleted the usralgo.ko from the bin/Debug directory and Built and downloaded the project - but did not get the usralgo.ko file back. This is supposed to be generated during the build process, correct?
  • 1 year later...
Posted
I'm having a similar problem. I create a user servo algorithm. I assign it to a motor. It compiles correctly, creates a usralgo.ko file and the file downloads (doing build and download all) but the UserAlso.ServoCtrlAddr[0] and UserAlso.ServoCtrlAddr[1] always equal 0 and the motor servo always uses the default PID. Since the address are 0, I obviously cannot assign them. Is there something it the project that may be missing. I've done this repetitively manually deleting the ko file and doing a clean to ensure nothing is left behind but end up with the same results. So, in the end, it was because fmin and fmax are not in this version of math.h. The real problem is that the IDE and all error logs did not report the error. They downloaded and just did not successfully run. It is very difficult to find errors in userAlgo with this setup. We found it by creating a duplicate of it as a background c program.
Guest
This topic is now closed to further replies.

×
×
  • Create New...