[ros-users] C++ type conversion error

ibwood ianbenjiman at hotmail.com
Thu Jul 29 19:09:33 UTC 2010

Hi everyone,

I was really close to successfully compiling a code of mine, when I ran into
this error:

"expected constructor, destructor, or type conversion before "=" token"

in lines 126-129 (with ms1, ms2, ms3, ms4 assignments).  What does it mean
and how can I fix it?

Here is the code:

 #define PI = 3.14159265358979323846264338327950288419716

 #include "ros/ros.h"
 #include "std_msgs/String.h"

 #include <sstream>
 #include <cmath>
 #include <iostream>

 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <limits.h>
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <termios.h>
 #include <unistd.h>

 using namespace std;

 const double r=0.125, R=0.55, ratio=127;	// initialize constants

 int main(int argc, char **argv)
	unsigned ms1, ms2, ms3, ms4;			//motor speeds of omnimaxbot	
	int i, j, wr, rd, x=0, y=0, z=0, fd, numSent=0;
 	char parseChar[1], stringIn[50];

 	// unsigned long bytes_read	= 0;		//Number of bytes read from port
 	// unsigned long bytes_written	= 0;		//Number of bytes written to the port

 	int bStatus;
 	struct termios options;		//Contains various port settings


 	// attempt to open serial port

 	fd = open("/dev/HCS12",O_RDWR | O_NOCTTY | O_NDELAY);

	// set settings for serial port 

 	system("stty -F /dev/HCS12 115200 cs8 -cstopb -parity -icanon hupcl
-crtscts min 1 time 1");

 	// check for errors opening port	

 	if (fd == -1 )


		printf("open_port: Unable to open /dev/HCS12");


 	else // if no error


 		fcntl(fd, F_SETFL,0);

		printf("Test Port HCS12 has been successfully opened and %d is the file


 	// get current settings of serial ports
 	tcgetattr(fd, &options);

 	// set the read and write speeds
 	cfsetispeed(&options, B115200);
 	cfsetospeed(&options, B115200);

 	// set parity
 	options.c_cflag &= ~CSIZE;
 	options.c_cflag |= CS8;

 	if (bStatus != 0)
		cout << "byte status error!" << endl;

	// initalize node
	ros::init(argc, argv, "joyTalker");
	ros::NodeHandle joyTalker;

	// Publish to topic joyChatter
	ros::Publisher pub = joyTalker.advertise<std_msgs::String>("joyChatter",

	ros::Rate r(10);

	while (joyTalker.ok())

		for(j=0; j<50; j++)


		while(parseChar[0] != 10)
			if(i==50)	// exceeds the allowable size

			rd = read(fd,parseChar,1);
			// printf("%s ",parseChar);
			if ((parseChar[0] > 43) && ((parseChar[0] < 58) || (parseChar[0]==32)))
			if (wr != 0)
				cout << "byte status error!!!" << endl;
			// kinematics of the omnimaxbot
			ms1 = ((x/sqrt(2))+y+(R*tan((z/ratio)*(2*PI))))/((2*PI)*r);
			ms2 = (-(x/sqrt(2))+y+(R*tan((z/ratio)*(2*PI))))/((2*PI)*r);
			ms3 = ((x/sqrt(2))+y-(R*tan((z/ratio)*(2*PI))))/((2*PI)*r);
			ms4 = (-(x/sqrt(2))+y-(R*tan((z/ratio)*(2*PI))))/((2*PI)*r);
			fd = open("/dev/Driver1&2",O_RDWR | O_NOCTTY | O_NDELAY);
			if (fd == -1 )


				perror("open_port: Unable to open /dev/Driver1&2");

			// send to ROS node for communication
			numSent = sprintf(stringIn, "%3d,%3d\n", ms1, ms2);
			// status[0] = Serial_SendBlock(stringIn, numSent, &numSentS);
			fd = open("/dev/Driver3&4",O_RDWR | O_NOCTTY | O_NDELAY);
			if (fd == -1 )


				perror("open_port: Unable to open /dev/Driver3&4");

			// send to ROS node for communication
			numSent = sprintf(stringIn, "%3d,%3d\n", ms3, ms4);
			// status[0] = Serial_SendBlock(stringIn, numSent, &numSentS);

		printf("got this string %s\n",stringIn);

		// convert message to string for ROS node communication
		std_msgs::String msg;
		std::stringstream ss;
		ss << stringIn;
		ROS_INFO("%s", ss.str().c_str());
		msg.data = ss.str();
		// publish data under topic joyChatter

 return 0;

View this message in context: http://ros-users.122217.n3.nabble.com/C-type-conversion-error-tp1004701p1004701.html
Sent from the ROS-Users mailing list archive at Nabble.com.

The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
ros-users mailing list
ros-users at lists.sourceforge.net

More information about the ros-users mailing list