If it's not even getting to the part where it's printing "e", which occurs before any ROS-related code, then this is not ROS related and is not appropriate for this list.<div><br></div><div>The support page has guidelines for what is appropriate: <a href="http://www.ros.org/wiki/Support">http://www.ros.org/wiki/Support</a></div>
<div><br></div><div>Josh<br><br><div class="gmail_quote">On Wed, Aug 11, 2010 at 10:48 AM, ibwood <span dir="ltr"><<a href="mailto:ianbenjiman@hotmail.com">ianbenjiman@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Hi everyone,<br>
<br>
I have some C++ code that compiles without any errors. The code is designed<br>
to communicate with the usb ports and send values to motor drivers for<br>
operation with a joystick. I'm having trouble deciphering why it is not<br>
outputting "e" and continuing on to initialize and publish to the joyChatter<br>
node. Please tell me if I have any syntax incorrect. Here is the code:<br>
<br>
#include "ros/ros.h"<br>
#include "std_msgs/String.h"<br>
<br>
#include <sstream><br>
#include <cmath><br>
#include <iostream><br>
<br>
#include <sys/ioctl.h><br>
#include <sys/types.h><br>
#include <sys/stat.h><br>
#include <stdio.h><br>
#include <limits.h><br>
#include <string.h><br>
#include <fcntl.h><br>
#include <errno.h><br>
#include <termios.h><br>
#include <unistd.h><br>
<br>
#define PI 3.14159265358979323846264338327950288419716<br>
<br>
using namespace std;<br>
<br>
const double CIRC=0.7853981633974483, R=0.55, ratio=127; // initialize<br>
constants<br>
<br>
int main(int argc, char **argv)<br>
{<br>
int ms1, ms2, ms3, ms4; //motor speeds of omnimaxbot<br>
int i, j, wr, rd, x=0, y=0, z=0, fd, fd1, fd2, numSent=0;<br>
char parseChar[1], stringIn[50], mc_char;<br>
<br>
// unsigned long bytes_read = 0; //Number of bytes read from port<br>
// unsigned long bytes_written = 0; //Number of bytes written to the port<br>
<br>
<br>
<br>
<br>
// attempt to open serial port connected to the microprocessor<br>
<br>
fd = open("/dev/HCS12",O_RDWR | O_NOCTTY | O_NDELAY);<br>
<br>
<br>
system("stty -F /dev/HCS12 115200 cs8 -cstopb -parity -icanon hupcl<br>
-crtscts min 1 time 1"); // set settings for HCS12 microcontroller<br>
<br>
<br>
// check for errors opening port<br>
<br>
if (fd == -1 )<br>
<br>
{<br>
<br>
printf("open_port: Unable to open /dev/HCS12\n");<br>
<br>
}<br>
<br>
<br>
else // if no error<br>
<br>
{<br>
<br>
fcntl(fd,F_SETFL,0);<br>
<br>
printf("Test Port HCS12 has been successfully opened and %d is the file<br>
description\n",fd);<br>
<br>
}<br>
<br>
//open serial port connected to motor driver for motors 1 and 2<br>
fd1 = open("/dev/Driver12",O_RDWR | O_NOCTTY | O_NDELAY);<br>
<br>
system("stty -F /dev/Driver12 9600 cs8 -cstopb -parity -icanon hupcl<br>
-crtscts min 1 time 1"); //settings for motor drivers<br>
<br>
if (fd1 == -1 )<br>
<br>
{<br>
<br>
perror("open_port: Unable to open /dev/Driver12\n");<br>
<br>
}<br>
<br>
else // if no error<br>
<br>
{<br>
<br>
fcntl(fd1,F_SETFL,0);<br>
<br>
printf("Test Port Driver12 has been successfully opened and %d is the file<br>
description\n",fd1);<br>
<br>
}<br>
<br>
//open serial port connected to motor driver for motors 3 and 4<br>
fd2 = open("/dev/Driver34",O_RDWR | O_NOCTTY | O_NDELAY);<br>
<br>
system("stty -F /dev/Driver34 9600 cs8 -cstopb -parity -icanon hupcl<br>
-crtscts min 1 time 1"); //settings for motor drivers<br>
<br>
if (fd2 == -1 )<br>
<br>
{<br>
<br>
perror("open_port: Unable to open /dev/Driver34\n");<br>
<br>
}<br>
<br>
else // if no error<br>
<br>
{<br>
<br>
fcntl(fd2,F_SETFL,0);<br>
<br>
printf("Test Port Driver34 has been successfully opened and %d is the file<br>
description\n",fd2);<br>
<br>
}<br>
<br>
printf("e");<br>
// initalize node<br>
ros::init(argc, argv, "joyTalker");<br>
ros::NodeHandle joyTalker;<br>
printf("f");<br>
// Publish to topic joyChatter<br>
ros::Publisher pub = joyTalker.advertise<std_msgs::String>("joyChatter",<br>
1000);<br>
printf("0");<br>
ros::Rate r(10);<br>
printf("1");<br>
while (joyTalker.ok())<br>
{<br>
parseChar[0]=0;<br>
<br>
for(j=0; j<50; j++)<br>
{<br>
stringIn[j]=0; //initialize the string<br>
}<br>
<br>
i=0;<br>
printf("2");<br>
while(parseChar[0] != 10)<br>
{<br>
if(i==50) // exceeds the allowable size<br>
{<br>
break;<br>
}<br>
<br>
rd = read(fd,parseChar,1);<br>
// printf("%s ",parseChar);<br>
if ((parseChar[0] > 43) && ((parseChar[0] < 58) || (parseChar[0]==32)))<br>
{<br>
stringIn[i]=parseChar[0];<br>
i++;<br>
}<br>
<br>
// kinematics of the omnimaxbot<br>
ms1 = ((x/sqrt(2))+y+(R*tan((z/ratio)*(2*PI))))/CIRC;<br>
ms2 = (-(x/sqrt(2))+y+(R*tan((z/ratio)*(2*PI))))/CIRC;<br>
ms3 = ((x/sqrt(2))+y-(R*tan((z/ratio)*(2*PI))))/CIRC;<br>
ms4 = (-(x/sqrt(2))+y-(R*tan((z/ratio)*(2*PI))))/CIRC;<br>
<br>
if(ms1<0) //Motor Controller 1, Port A, Motor 1<br>
{<br>
ms1=-ms1;<br>
mc_char = 'a';<br>
}<br>
else<br>
{<br>
mc_char = 'A';<br>
}<br>
//write data to the specified port<br>
numSent = sprintf(stringIn, "!%c%d", mc_char, ms1);<br>
wr = write(fd1,stringIn,numSent);<br>
<br>
if(ms2<0) //Motor Controller 1, Port B, Motor 2<br>
{<br>
ms2=-ms2;<br>
mc_char = 'a';<br>
}<br>
else<br>
{<br>
mc_char = 'A';<br>
}<br>
<br>
numSent = sprintf(stringIn, "!%c%d", mc_char, ms2);<br>
wr = write(fd1,stringIn,numSent);<br>
<br>
if(ms3<0) //Motor Controller 2, Port A, Motor 3<br>
{<br>
ms3=-ms3;<br>
mc_char = 'b';<br>
}<br>
else<br>
{<br>
mc_char = 'B';<br>
}<br>
numSent = sprintf(stringIn, "!%c%d", mc_char, ms3);<br>
wr = write(fd2,stringIn,numSent);<br>
<br>
if(ms4<0) //Motor Controller 2, Port B, Motor 4<br>
{<br>
ms4=-ms4;<br>
mc_char = 'b';<br>
}<br>
else<br>
{<br>
mc_char = 'B';<br>
}<br>
numSent = sprintf(stringIn, "!%c%d", mc_char, ms4);<br>
wr = write(fd2,stringIn,numSent);<br>
}<br>
printf("got this string %s\n",stringIn);<br>
printf("8");<br>
// convert message to string for ROS node communication<br>
std_msgs::String msg;<br>
std::stringstream ss;<br>
ss << stringIn;<br>
ROS_INFO("%s", ss.str().c_str());<br>
msg.data = ss.str();<br>
// publish data under topic joyChatter<br>
pub.publish(msg);<br>
<br>
ros::spinOnce();<br>
}<br>
<br>
return 0;<br>
}<br>
<br>
--<br>
View this message in context: <a href="http://ros-users.122217.n3.nabble.com/ROS-node-publishing-not-responsive-in-C-code-tp1091286p1091286.html" target="_blank">http://ros-users.122217.n3.nabble.com/ROS-node-publishing-not-responsive-in-C-code-tp1091286p1091286.html</a><br>
Sent from the ROS-Users mailing list archive at Nabble.com.<br>
<br>
------------------------------------------------------------------------------<br>
This SF.net email is sponsored by<br>
<br>
Make an app they can't live without<br>
Enter the BlackBerry Developer Challenge<br>
<a href="http://p.sf.net/sfu/RIM-dev2dev" target="_blank">http://p.sf.net/sfu/RIM-dev2dev</a><br>
_______________________________________________<br>
ros-users mailing list<br>
<a href="mailto:ros-users@lists.sourceforge.net">ros-users@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/ros-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/ros-users</a><br>
_______________________________________________<br>
ros-users mailing list<br>
<a href="mailto:ros-users@code.ros.org">ros-users@code.ros.org</a><br>
<a href="https://code.ros.org/mailman/listinfo/ros-users" target="_blank">https://code.ros.org/mailman/listinfo/ros-users</a><br>
</blockquote></div><br></div>