Are there have strcpy ,sprintf,strcat in RTAI?
- liangliming
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
22 Jul 2013 15:11 - 22 Jul 2013 17:57 #36878
by liangliming
Are there have strcpy ,sprintf,strcat in RTAI? was created by liangliming
Dear all,
I am using Turbo PMAC2A PC/104 to control a robot,the PMAC connect the upper computer by ISA bus. The O.S of the computer is ubuntu10.04 kernel 2.6.32-122-rtai.
The upper computer is responsible for generat the position velocity and send them to the rotary buffer in PMAC. Because the robot require a quick response to the environment, thus a long delay are not permitted. Actually, we send the position every 10ms, and we want to guarantee that the rotary buffer should not hungry and also not too much comand lines remaining in the buffer, therefore, I initial two command lines in the rotary buffer.
I test it two times, and each were taken half an hour. and repeated 181000 times and also call the following functions to send command to PMAC, in the most of time, the send PVT time are small ,however in the 44390 while loop it takes more than 100ms , and also several times exceed several ms, which will cause the hungry of rotary buffer and are not permitted in my system.
What's wrong with it? Whether there have some special fuction in RTAI to replace them? Can you help me?
Any available advice are appreciated.
Thanks in advance!
I am using Turbo PMAC2A PC/104 to control a robot,the PMAC connect the upper computer by ISA bus. The O.S of the computer is ubuntu10.04 kernel 2.6.32-122-rtai.
The upper computer is responsible for generat the position velocity and send them to the rotary buffer in PMAC. Because the robot require a quick response to the environment, thus a long delay are not permitted. Actually, we send the position every 10ms, and we want to guarantee that the rotary buffer should not hungry and also not too much comand lines remaining in the buffer, therefore, I initial two command lines in the rotary buffer.
I test it two times, and each were taken half an hour. and repeated 181000 times and also call the following functions to send command to PMAC, in the most of time, the send PVT time are small ,however in the 44390 while loop it takes more than 100ms , and also several times exceed several ms, which will cause the hungry of rotary buffer and are not permitted in my system.
What's wrong with it? Whether there have some special fuction in RTAI to replace them? Can you help me?
Any available advice are appreciated.
Thanks in advance!
//This file shows the function add position and velocity to Rotary buffer, and the function for sending command to PMAC.
void PMAC::RotaryBufferAddPositionVelocityLine(int* pos_m,int* vel_m)
{
char cmd[256];
char value[15];
string answ;
strcpy(cmd,"OPEN ROT");//NOTE:Should change to coordinate system.
SendCmd(cmd);
strcpy(cmd,"X");//From strcat change to strcpy
sprintf(value, " %d", pos_m[0]);
strcat(cmd,value);
strcat(cmd,":");
sprintf(value, " %d", vel_m[0]);
strcat(cmd,value);
strcat(cmd," Y");
sprintf(value, " %d", pos_m[1]);
strcat(cmd,value);
strcat(cmd,":");
sprintf(value, " %d", vel_m[1]);
strcat(cmd,value);
SendCmd(cmd);
strcpy(cmd,"CLOSE");
SendCmd(cmd);
}
void PMAC::SendCmd(char* cmd)
{
if(pmac_get_response(pmac_dev, cmd) == -ENODEV)
printf("No device found\n");
return;
}
Last edit: 22 Jul 2013 17:57 by liangliming. Reason: To complete the thread
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 761
22 Jul 2013 18:11 #36881
by ArcEye
Replied by ArcEye on topic Are there have strcpy ,sprintf,strcat in RTAI?
Hi
Have a look at the bottom of this page at the RTAPI calls
www.linuxcnc.org/docs/devel/html/
There are rtapi_snprintf(), rtapi_vsnprintf() and rtapi_print_msg() for starters
regards
Have a look at the bottom of this page at the RTAPI calls
www.linuxcnc.org/docs/devel/html/
There are rtapi_snprintf(), rtapi_vsnprintf() and rtapi_print_msg() for starters
regards
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 761
22 Jul 2013 20:18 - 22 Jul 2013 20:22 #36886
by ArcEye
Replied by ArcEye on topic Are there have strcpy ,sprintf,strcat in RTAI?
I have nothing to test it with, but does something like this work any better?
static char opener[ ] = "OPEN ROT\0";
static char closer[ ] = "CLOSE\0";
void PMAC::RotaryBufferAddPositionVelocityLine(int* pos_m,int* vel_m)
{
char cmd[80];
SendCmd(opener);
rtapi_snprintf(cmd, 80, "X %d: %d Y %d: %d",pos_m[0], vel_m[0], pos_m[1], vel_m[1]);
SendCmd(cmd);
SendCmd(closer);
}
void PMAC::SendCmd(char* cmd)
{
if(pmac_get_response(pmac_dev, cmd) == -ENODEV)
rtapi_print_msg(RTAPI_ERR,"No device found");
return;
}
Last edit: 22 Jul 2013 20:22 by ArcEye.
The following user(s) said Thank You: liangliming
Please Log in or Create an account to join the conversation.
- liangliming
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
22 Jul 2013 20:54 #36888
by liangliming
Replied by liangliming on topic Are there have strcpy ,sprintf,strcat in RTAI?
Thanks for your information, I was read what you told me before , but I found it was described like the standard C printf functions,so it takes time for me to understand how to use it. Now, you are very kind to give me the exact code, so I will test it and then show you the result.
I have nothing to test it with, but does something like this work any better?
static char opener[ ] = "OPEN ROT\0"; static char closer[ ] = "CLOSE\0"; void PMAC::RotaryBufferAddPositionVelocityLine(int* pos_m,int* vel_m) { char cmd[80]; SendCmd(opener); rtapi_snprintf(cmd, 80, "X %d: %d Y %d: %d",pos_m[0], vel_m[0], pos_m[1], vel_m[1]); SendCmd(cmd); SendCmd(closer); } void PMAC::SendCmd(char* cmd) { if(pmac_get_response(pmac_dev, cmd) == -ENODEV) rtapi_print_msg(RTAPI_ERR,"No device found"); return; }
Please Log in or Create an account to join the conversation.
- liangliming
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
22 Jul 2013 21:35 #36891
by liangliming
Replied by liangliming on topic Are there have strcpy ,sprintf,strcat in RTAI?
I have already code as you said, but the eclipse CDT shows : function "rtapi_snprintf" could not be resolved
i include the rtai_api.h in my code ,but it seems error.
What is the right header I should include in my code? How to make it works??
Thank you very much!
i include the rtai_api.h in my code ,but it seems error.
What is the right header I should include in my code? How to make it works??
Thank you very much!
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 761
22 Jul 2013 22:57 - 22 Jul 2013 22:58 #36892
by ArcEye
Replied by ArcEye on topic Are there have strcpy ,sprintf,strcat in RTAI?
Hi
The header in linuxcnc is rtapi.h and the library to link against appears to be liblinuxcnchal.so
Of course if you are not using Linuxcnc, just RTAI, this does not help you much, but this is a Linuxcnc forum, so I assumed that you are using it.
regards
The header in linuxcnc is rtapi.h and the library to link against appears to be liblinuxcnchal.so
Of course if you are not using Linuxcnc, just RTAI, this does not help you much, but this is a Linuxcnc forum, so I assumed that you are using it.
regards
Last edit: 22 Jul 2013 22:58 by ArcEye.
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 761
22 Jul 2013 23:12 - 22 Jul 2013 23:13 #36893
by ArcEye
Replied by ArcEye on topic Are there have strcpy ,sprintf,strcat in RTAI?
If you are just using RTAI not Linuxcnc, try replacing the rtapi_snprintf() with sprintf()
( sprintf(cmd, "X %d: %d Y %d: %d",pos_m[0], vel_m[0], pos_m[1], vel_m[1]); )
Apparantly rt_printk() uses it internally, so it must be rt thread safe
You can then use rt_printk() to print the error message, but you will need to look up headers / libraries, not an area I know
mail.rtai.org/pipermail/rtai/2002-December/001890.html
regards
( sprintf(cmd, "X %d: %d Y %d: %d",pos_m[0], vel_m[0], pos_m[1], vel_m[1]); )
Apparantly rt_printk() uses it internally, so it must be rt thread safe
You can then use rt_printk() to print the error message, but you will need to look up headers / libraries, not an area I know
mail.rtai.org/pipermail/rtai/2002-December/001890.html
regards
Last edit: 22 Jul 2013 23:13 by ArcEye.
The following user(s) said Thank You: liangliming
Please Log in or Create an account to join the conversation.
- liangliming
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
23 Jul 2013 08:54 - 23 Jul 2013 09:01 #36926
by liangliming
Replied by liangliming on topic Are there have strcpy ,sprintf,strcat in RTAI?
Hi,
Thanks for your information, I have download the ubuntu10.04 kernel 2.6.32-rtai from this website, I ask question in other formus,but no one answer me, so I came here and your are very nice and patient to help me.
I am new for this O.S even new to linux. I am not clear whether I am using Linuxcnc? I can only find the liblinuxcnchal.so.0(Not liblinuxcnchal.so) in filesystem, However, I can not find the rtapi.h in it.
since I have change the code to ( sprintf(cmd, "X %d: %d Y %d: %d",pos_m[0], vel_m[0], pos_m[1], vel_m[1]); Test it again , the result were not improved , and about every five minutes in the begining, it wil cost long time to finish the calling of the function. You can see the exactly result in the attachments. I am not sure whether it was related to use the sprintf.
The table shows the 10 largest terms of calling the PVT function in total 181000 cycles.
Actually, I have already use the rt_printk() to show the time.
By the way, can I use the rtapi_snprintf() for test, and how?
Thank you very much!.
Thanks for your information, I have download the ubuntu10.04 kernel 2.6.32-rtai from this website, I ask question in other formus,but no one answer me, so I came here and your are very nice and patient to help me.
I am new for this O.S even new to linux. I am not clear whether I am using Linuxcnc? I can only find the liblinuxcnchal.so.0(Not liblinuxcnchal.so) in filesystem, However, I can not find the rtapi.h in it.
since I have change the code to ( sprintf(cmd, "X %d: %d Y %d: %d",pos_m[0], vel_m[0], pos_m[1], vel_m[1]); Test it again , the result were not improved , and about every five minutes in the begining, it wil cost long time to finish the calling of the function. You can see the exactly result in the attachments. I am not sure whether it was related to use the sprintf.
The table shows the 10 largest terms of calling the PVT function in total 181000 cycles.
Actually, I have already use the rt_printk() to show the time.
By the way, can I use the rtapi_snprintf() for test, and how?
Thank you very much!.
Last edit: 23 Jul 2013 09:01 by liangliming.
Please Log in or Create an account to join the conversation.
- liangliming
- Offline
- New Member
Less
More
- Posts: 6
- Thank you received: 0
23 Jul 2013 10:53 #36927
by liangliming
Replied by liangliming on topic Are there have strcpy ,sprintf,strcat in RTAI?
well, I have try to use rt_printk as the following command line.The IDE did not remind errors, however, When I executed the program ,It does not work, and then I printf the cmd, I found it was totally wrong.
So what the right format to use the rt_printk in this case??
Thank you very much!
rt_printk(cmd, "X %d: %d Y %d: %d",pos_m[0], vel_m[0], pos_m[1], vel_m[1]);
So what the right format to use the rt_printk in this case??
Thank you very much!
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 761
23 Jul 2013 15:06 - 23 Jul 2013 15:07 #36930
by ArcEye
Replied by ArcEye on topic Are there have strcpy ,sprintf,strcat in RTAI?
Hi,
Unfortunately I think you are in the wrong place, you need to look at www.rtai.org and google for the various things you want to find out.
Being new to linux as well is not going to make things easier.
Unless you are programming a Linuxcnc realtime module, then you cannot use rtapi_snprintf() it is part of the Linuxcnc api.
Likewise rtapi.h needs the sources or linuxcnc-dev installed to obtain.
liblinuxcnchal.so does exist, it is a symlink for .so.0
rt_printk() is the same format as printf(), not sprintf(). It prints to stdout (or /var/log/messages) not to a buffer.
I can understand why you installed Linuxcnc, because it has a ready built rt-kernel and realtime,
but unless you are going to use Linuxcnc to control your robot, that is as far as I can help you
regards
Unfortunately I think you are in the wrong place, you need to look at www.rtai.org and google for the various things you want to find out.
Being new to linux as well is not going to make things easier.
Unless you are programming a Linuxcnc realtime module, then you cannot use rtapi_snprintf() it is part of the Linuxcnc api.
Likewise rtapi.h needs the sources or linuxcnc-dev installed to obtain.
liblinuxcnchal.so does exist, it is a symlink for .so.0
rt_printk() is the same format as printf(), not sprintf(). It prints to stdout (or /var/log/messages) not to a buffer.
I can understand why you installed Linuxcnc, because it has a ready built rt-kernel and realtime,
but unless you are going to use Linuxcnc to control your robot, that is as far as I can help you
regards
Last edit: 23 Jul 2013 15:07 by ArcEye.
The following user(s) said Thank You: liangliming
Please Log in or Create an account to join the conversation.
Time to create page: 0.087 seconds