错误:____ 未在此范围内声明
当我尝试编译我的publishJoints代码时,我不断收到错误消息,指出超出范围。
这是publishJoints.cpp代码,
#include <string>
#include <ros/ros.h>
#include <sensor_msgs/JointState.h>
#include <vector>
#include <stdio.h>
#include "GestureFile.h"
#define DOF 19
#define DIR_mt4 1
#define DIR_ma14 1
#define DIR_ma12 1
#define COUNT_DEG 2222 //encoder count per deg
enum parts
{
m3joint_mt4_j0,
m3joint_mt4_j1,
m3joint_slave_mt4_j2,
left_shoulder_pan_joint,
left_shoulder_lift_joint,
left_elbow_pan_joint,
left_elbow_lift_joint,
m3joint_ma14_j4,
m3joint_ma14_j5,
m3joint_ma14_j6,
right_shoulder_pan_joint,
right_shoulder_lift_joint,
right_elbow_pan_joint,
right_elbow_lift_joint,
m3joint_ma12_j4,
m3joint_ma12_j5,
m3joint_ma12_j6,
Neck_Casing,
Head_Casing,
};
int main(int argc, char** argv) {
ros::init(argc, argv, "publishJoints");
ros::NodeHandle n;
ros::Publisher joint_pub = n.advertise<sensor_msgs::JointState>("joint_states", 100);
ros::Rate loop_rate(100000);
const double degree = M_PI/180;
// robot state
double swivel=0;
double tilt=0;
// message declarations
sensor_msgs::JointState joint_state;
joint_state.name.resize(19);
joint_state.position.resize(19);
while (ros::ok()) {
//update joint_state
joint_state.header.stamp = ros::Time::now();
swivel=0;
joint_state.name[0] ="m3joint_mt4_j0";
joint_state.position[0] = swivel;
joint_state.name[1] ="m3joint_mt4_j1";
joint_state.position[1] = swivel;
joint_state.name[2] ="m3joint_slave_mt4_j2";
joint_state.position[2] = tilt;
joint_state.name[3] ="left_shoulder_pan_joint";
joint_state.position[3] = tilt;
joint_state.name[4] ="left_shoulder_lift_joint";
joint_state.position[4] = tilt;
joint_state.name[5] ="left_elbow_pan_joint";
joint_state.position[5] = tilt;
joint_state.name[6] ="left_elbow_lift_joint";
joint_state.position[6] = tilt;
joint_state.name[7] ="m3joint_ma14_j4";
joint_state.position[7] = swivel;
joint_state.name[8] ="m3joint_ma14_j5";
joint_state.position[8] = swivel;
joint_state.name[9] ="m3joint_ma14_j6";
joint_state.position[9] = swivel;
joint_state.name[10] ="right_shoulder_pan_joint";
joint_state.position[10] = swivel;
joint_state.name[11] ="right_shoulder_lift_joint";
joint_state.position[11] = swivel;
joint_state.name[12] ="right_elbow_pan_joint";
joint_state.position[12] = swivel;
joint_state.name[13] ="right_elbow_lift_joint";
joint_state.position[13] = swivel;
joint_state.name[14] ="m3joint_ma12_j4";
joint_state.position[14] = tilt;
joint_state.name[15] ="m3joint_ma12_j5";
joint_state.position[15] = tilt;
joint_state.name[16] ="m3joint_ma12_j6" ;
joint_state.position[16] = tilt;
joint_state.name[17] ="Neck_Casing" ;
joint_state.position[17] = tilt;
joint_state.name[18] ="Head_Casing" ;
joint_state.position[18] = tilt;
tilt += 0.000001;
//send the joint state and transform
joint_pub.publish(joint_state);
// This will adjust as needed per iteration
loop_rate.sleep();
}
return 0;
}
int readDynamicGestureFile(points_body_t gesture[][10000], int *numOfCoords)
{
int number=0;
char buff[500];
double position[DOF]={0};
int time;
FILE* ifp=NULL;
//there is only one file to read
memset(&buff,0,sizeof(buff));
if ( fopen_s(&ifp, "C://share/Motion.csv","r") != 0 )
{
AfxMessageBox( "Cannot open Motion File that was sent");
return 0;
}
do {
fgets(buff,500,ifp);
int result = sscanf_s(buff, "%d %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf",
&time,
&position[0], //m3joint_mt4_j0
&position[1], //m3joint_mt4_j1
&position[2], //m3joint_slave_mt4_j2
&position[3], //left_shoulder_pan_joint
&position[4], //left_shoulder_lift_joint
&position[5], //left_elbow_pan_joint
&position[6], //left_elbow_lift_joint
&position[7], //m3joint_ma14_j4
&position[8], //m3joint_ma14_j5
&position[9], //m3joint_ma14_j6
&position[10], //right_shoulder_pan_joint
&position[11], //right_shoulder_lift_joint
&position[12], //right_elbow_pan_joint
&position[13], //right_elbow_lift_joint
&position[14], //m3joint_ma12_j4
&position[15], //m3joint_ma12_j5
&position[16], //m3joint_ma12_j6
&position[17], //Neck_Casing
&position[18] //Head_Casing
);
//*********************//
// Conversion Matrix //
//*********************//
gesture[0][number].m3joint_mt4_j0 = (int)( 0 );
//gesture[0][number].ptorso_1 = (int)( DIR_T1 * -position[1] );
gesture[0][number].m3joint_mt4_j1 = (int)( 0 );
/////////////////////////////////////////////////////////////////////////
gesture[0][number].m3joint_slave_mt4_j2 = (int)( DIR_mt4 * COUNT_DEG * (-position[2]) );
gesture[0][number].left_shoulder_pan_joint = (int)( DIR_ma14 * COUNT_DEG * -position[3] );
gesture[0][number].left_shoulder_lift_joint = (int)( DIR_ma14 * COUNT_DEG * position[4] );
////////////////////////////////////////////////////////////////
gesture[0][number].left_elbow_pan_joint = (int)( DIR_ma14 * COUNT_DEG * (position[5] + 90 ) );
gesture[0][number].left_elbow_lift_joint = (int)( DIR_ma14 * COUNT_DEG * position[6] );
gesture[0][number].m3joint_ma14_j4 = (int)( DIR_ma14 * COUNT_DEG * ( -position[7] -90) );
gesture[0][number].m3joint_ma14_j5 = (int)( COUNT_DEG * -position[8] );
gesture[0][number].m3joint_ma14_j6 = (int)( COUNT_DEG * -position[9] );
gesture[0][number].right_shoulder_pan_joint = (int)( COUNT_DEG * -position[10] );
//gesture[0][number].right_shoulder_lift_joint = (int)( COUNT_DEG * position[11] );
///////////////////////////////////////////////////////////////////
gesture[0][number].right_elbow_pan_joint = (int)( COUNT_DEG * ( -position[12] - 90 ) );
gesture[0][number].right_elbow_lift_joint = (int)( COUNT_DEG * position[13] );
//gesture[0][number].pR_upper_2 = (int)( COUNT_DEG * ( 90-position[R_upper_2] ) );
gesture[0][number].m3joint_ma12_j4 = (int)( COUNT_DEG * ( -position[14] + 90 ) );
gesture[0][number].m3joint_ma12_j5= (int)( COUNT_DEG * -position[15] );
gesture[0][number].m3joint_ma12_j6= (int)( COUNT_DEG * -position[16] );
gesture[0][number].Neck_Casing = (int)( COUNT_DEG * -position[17] );
gesture[0][number].Head_Casing = (int)( COUNT_DEG * position[18] );
number++;
} while(!feof(ifp));
numOfCoords[0] = number;
fclose(ifp);
return 1;
}
下面是我编译时的错误消息。
错误:“fopen_s”未在此范围内声明
错误:“AfxMessageBox”未在此范围内声明
错误:“sscanf_s”未在此范围内声明
任何帮助将不胜感激。
When i try to compile my publishJoints code i keep getting errors saying out of scope.
here is the publishJoints.cpp code
#include <string>
#include <ros/ros.h>
#include <sensor_msgs/JointState.h>
#include <vector>
#include <stdio.h>
#include "GestureFile.h"
#define DOF 19
#define DIR_mt4 1
#define DIR_ma14 1
#define DIR_ma12 1
#define COUNT_DEG 2222 //encoder count per deg
enum parts
{
m3joint_mt4_j0,
m3joint_mt4_j1,
m3joint_slave_mt4_j2,
left_shoulder_pan_joint,
left_shoulder_lift_joint,
left_elbow_pan_joint,
left_elbow_lift_joint,
m3joint_ma14_j4,
m3joint_ma14_j5,
m3joint_ma14_j6,
right_shoulder_pan_joint,
right_shoulder_lift_joint,
right_elbow_pan_joint,
right_elbow_lift_joint,
m3joint_ma12_j4,
m3joint_ma12_j5,
m3joint_ma12_j6,
Neck_Casing,
Head_Casing,
};
int main(int argc, char** argv) {
ros::init(argc, argv, "publishJoints");
ros::NodeHandle n;
ros::Publisher joint_pub = n.advertise<sensor_msgs::JointState>("joint_states", 100);
ros::Rate loop_rate(100000);
const double degree = M_PI/180;
// robot state
double swivel=0;
double tilt=0;
// message declarations
sensor_msgs::JointState joint_state;
joint_state.name.resize(19);
joint_state.position.resize(19);
while (ros::ok()) {
//update joint_state
joint_state.header.stamp = ros::Time::now();
swivel=0;
joint_state.name[0] ="m3joint_mt4_j0";
joint_state.position[0] = swivel;
joint_state.name[1] ="m3joint_mt4_j1";
joint_state.position[1] = swivel;
joint_state.name[2] ="m3joint_slave_mt4_j2";
joint_state.position[2] = tilt;
joint_state.name[3] ="left_shoulder_pan_joint";
joint_state.position[3] = tilt;
joint_state.name[4] ="left_shoulder_lift_joint";
joint_state.position[4] = tilt;
joint_state.name[5] ="left_elbow_pan_joint";
joint_state.position[5] = tilt;
joint_state.name[6] ="left_elbow_lift_joint";
joint_state.position[6] = tilt;
joint_state.name[7] ="m3joint_ma14_j4";
joint_state.position[7] = swivel;
joint_state.name[8] ="m3joint_ma14_j5";
joint_state.position[8] = swivel;
joint_state.name[9] ="m3joint_ma14_j6";
joint_state.position[9] = swivel;
joint_state.name[10] ="right_shoulder_pan_joint";
joint_state.position[10] = swivel;
joint_state.name[11] ="right_shoulder_lift_joint";
joint_state.position[11] = swivel;
joint_state.name[12] ="right_elbow_pan_joint";
joint_state.position[12] = swivel;
joint_state.name[13] ="right_elbow_lift_joint";
joint_state.position[13] = swivel;
joint_state.name[14] ="m3joint_ma12_j4";
joint_state.position[14] = tilt;
joint_state.name[15] ="m3joint_ma12_j5";
joint_state.position[15] = tilt;
joint_state.name[16] ="m3joint_ma12_j6" ;
joint_state.position[16] = tilt;
joint_state.name[17] ="Neck_Casing" ;
joint_state.position[17] = tilt;
joint_state.name[18] ="Head_Casing" ;
joint_state.position[18] = tilt;
tilt += 0.000001;
//send the joint state and transform
joint_pub.publish(joint_state);
// This will adjust as needed per iteration
loop_rate.sleep();
}
return 0;
}
int readDynamicGestureFile(points_body_t gesture[][10000], int *numOfCoords)
{
int number=0;
char buff[500];
double position[DOF]={0};
int time;
FILE* ifp=NULL;
//there is only one file to read
memset(&buff,0,sizeof(buff));
if ( fopen_s(&ifp, "C://share/Motion.csv","r") != 0 )
{
AfxMessageBox( "Cannot open Motion File that was sent");
return 0;
}
do {
fgets(buff,500,ifp);
int result = sscanf_s(buff, "%d %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf %*c %lf",
&time,
&position[0], //m3joint_mt4_j0
&position[1], //m3joint_mt4_j1
&position[2], //m3joint_slave_mt4_j2
&position[3], //left_shoulder_pan_joint
&position[4], //left_shoulder_lift_joint
&position[5], //left_elbow_pan_joint
&position[6], //left_elbow_lift_joint
&position[7], //m3joint_ma14_j4
&position[8], //m3joint_ma14_j5
&position[9], //m3joint_ma14_j6
&position[10], //right_shoulder_pan_joint
&position[11], //right_shoulder_lift_joint
&position[12], //right_elbow_pan_joint
&position[13], //right_elbow_lift_joint
&position[14], //m3joint_ma12_j4
&position[15], //m3joint_ma12_j5
&position[16], //m3joint_ma12_j6
&position[17], //Neck_Casing
&position[18] //Head_Casing
);
//*********************//
// Conversion Matrix //
//*********************//
gesture[0][number].m3joint_mt4_j0 = (int)( 0 );
//gesture[0][number].ptorso_1 = (int)( DIR_T1 * -position[1] );
gesture[0][number].m3joint_mt4_j1 = (int)( 0 );
/////////////////////////////////////////////////////////////////////////
gesture[0][number].m3joint_slave_mt4_j2 = (int)( DIR_mt4 * COUNT_DEG * (-position[2]) );
gesture[0][number].left_shoulder_pan_joint = (int)( DIR_ma14 * COUNT_DEG * -position[3] );
gesture[0][number].left_shoulder_lift_joint = (int)( DIR_ma14 * COUNT_DEG * position[4] );
////////////////////////////////////////////////////////////////
gesture[0][number].left_elbow_pan_joint = (int)( DIR_ma14 * COUNT_DEG * (position[5] + 90 ) );
gesture[0][number].left_elbow_lift_joint = (int)( DIR_ma14 * COUNT_DEG * position[6] );
gesture[0][number].m3joint_ma14_j4 = (int)( DIR_ma14 * COUNT_DEG * ( -position[7] -90) );
gesture[0][number].m3joint_ma14_j5 = (int)( COUNT_DEG * -position[8] );
gesture[0][number].m3joint_ma14_j6 = (int)( COUNT_DEG * -position[9] );
gesture[0][number].right_shoulder_pan_joint = (int)( COUNT_DEG * -position[10] );
//gesture[0][number].right_shoulder_lift_joint = (int)( COUNT_DEG * position[11] );
///////////////////////////////////////////////////////////////////
gesture[0][number].right_elbow_pan_joint = (int)( COUNT_DEG * ( -position[12] - 90 ) );
gesture[0][number].right_elbow_lift_joint = (int)( COUNT_DEG * position[13] );
//gesture[0][number].pR_upper_2 = (int)( COUNT_DEG * ( 90-position[R_upper_2] ) );
gesture[0][number].m3joint_ma12_j4 = (int)( COUNT_DEG * ( -position[14] + 90 ) );
gesture[0][number].m3joint_ma12_j5= (int)( COUNT_DEG * -position[15] );
gesture[0][number].m3joint_ma12_j6= (int)( COUNT_DEG * -position[16] );
gesture[0][number].Neck_Casing = (int)( COUNT_DEG * -position[17] );
gesture[0][number].Head_Casing = (int)( COUNT_DEG * position[18] );
number++;
} while(!feof(ifp));
numOfCoords[0] = number;
fclose(ifp);
return 1;
}
following are the error messages when i compile.
error: ‘fopen_s’ was not declared in this scope
error: ‘AfxMessageBox’ was not declared in this scope
error: ‘sscanf_s’ was not declared in this scope
anyhelp would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
fopen_s
和sscanf_s
函数是 Microsoft 特定于 C 标准库的扩展,它们比默认存在的函数更不容易出错(危险)。如果您在非 Microsoft 平台上进行编译,那么您将需要找到这些函数的自定义实现。我不相信
gcc
或g++
有自己的这些函数版本。如果您在 Microsoft 平台上进行编译,则可能需要升级到较新版本的 Visual Studio。
The
fopen_s
andsscanf_s
functions are Microsoft-specific extensions to the C standard library that are less error-prone (dangerous) than the ones that are present by default.If you are compiling on a non-Microsoft platform, then you will need to find a custom implementation of these functions. I don't believe that
gcc
org++
have their own versions of these functions.If you are compiling on a Microsoft platform, then you may need to upgrade to a newer version of Visual Studio.