ros error while publishing servo topic controlled by voice commands [closed]
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); } ----------------------------------------
... 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?