ros error while publishing servo topic controlled by voice commands
The following error coming while uploading the code,
Creation of publisher failed: unpack requires a string argument of length 2
- code: String voice; #include
#include #include ros::NodeHandle nh; Servo
servo1; stdmsgs::UInt16 servomsg;
ros::Publisher pubrange( "/servo",
&servomsg); void allon(){
servo1.write(0); } void alloff(){
servo1.write(160); } void setup() {
nh.getHardware()->setBaud(38400);
nh.initNode();
nh.advertise(pubrange);
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");
servomsg.data=0;
pubrange.publish(&servomsg);
allon();} //Turn Off All Pins (Call
Function) else if(voice == "*hi"){
servomsg.data=120;
pubrange.publish(&servomsg);
alloff();} //Turn On All Pins (Call
Function)
pubrange.publish(&servo_msg);
voice=""; nh.spinOnce(); } delay(50);
}
----------------------------------------
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?
Asked by jubeira on 2017-11-15 12:52:11 UTC