ros error while publishing servo topic controlled by voice commands [closed]

asked 2017-11-15 06:57:31 -0500

anadgopi1994 gravatar image

The following error coming while uploading the code, Creation of publisher failed: unpack requires a string argument of length 2 - code: String voice; #include <ros.h> #include <std_msgs uint16.h=""> #include <servo.h> ros::NodeHandle nh; Servo servo1; std_msgs::UInt16 servo_msg; ros::Publisher pub_range( "/servo", &servo_msg); void allon(){ servo1.write(0); } void alloff(){ servo1.write(160); } void setup() { nh.getHardware()->setBaud(38400); nh.initNode(); nh.advertise(pub_range); Serial.begin(38400); servo1.attach(2); } void loop() { while (Serial.available()){ //Check if there is an available byte to read delay(10); //Delay added to make thing stable char c = Serial.read(); //Conduct a serial read if (c == '#') {break;} //Exit the loop when the # is detected after the word voice += c; //Shorthand for voice = voice + c } if (voice.length() > 0) { Serial.println(voice); if(voice == "hello") { Serial.println("success"); servo_msg.data=0; pub_range.publish(&servo_msg); allon();} //Turn Off All Pins (Call Function) else if(voice == "hi"){ servo_msg.data=120; pub_range.publish(&servo_msg); alloff();} //Turn On All Pins (Call Function) pub_range.publish(&servo_msg); voice=""; nh.spinOnce(); } delay(50); } ----------------------------------------

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant. Please see http://wiki.ros.org/Support for more details. by jubeira
close date 2018-09-26 08:59:48.291053

Comments

... the code is a bit hard to understand, can you format it properly and explain a bit more what you are trying to do? What does this have to do with Android?

jubeira gravatar image jubeira  ( 2017-11-15 11:52:11 -0500 )edit