ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

my hardware is working but on doing rostopic echo reading is 0.0

asked 2020-11-06 02:04:40 -0500

hafeez360 gravatar image

updated 2020-11-06 09:30:49 -0500

Code below:

 /*
   rosserial PubSub Example
   Prints "hello world!" and toggles led
*/

#include <ros.h>
#include <std_msgs/Float32.h>
#include <std_msgs/Int32.h>
#include <Servo.h>
#include <dht11.h>
#define DHT11PIN 4
int pos = 0 ;
dht11 DHT11;
ros::NodeHandle  nh;
Servo myservo;
void messageCb( const std_msgs::Int32& movewiper) {
  if (movewiper.data == 1) {
    myservo.write(180);
  }
  else {

    myservo.write(0);
    delay(15);

  }
}

ros::Subscriber<std_msgs::Int32> sub("Servo", messageCb );

std_msgs::Float32 humidity_range;
ros::Publisher humidity("humidity", &humidity_range);

//char hello[13] = "hello world!";

void setup()
{
  myservo.attach(9); //tell the arduino where the motor is attached and to control it
  nh.initNode(); //for initializing
  nh.advertise(humidity);
  nh.subscribe(sub);
}

void loop()
{
  int chk = DHT11.read(DHT11PIN);

  if (DHT11.humidity > 60) {
    for (pos = 0; pos <= 180; pos += 1) {
      myservo.write(pos);
      delay(15);
    }
  }

  else {
    myservo.write(0);
    delay(15);
  }

  humidity.publish( &humidity_range );
  nh.spinOnce();
  delay(500);
}
edit retag flag offensive close merge delete

Comments

Please properly format code snippets using the 101010 button.

jarvisschultz gravatar image jarvisschultz  ( 2020-11-06 09:30:17 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-11-06 20:55:46 -0500

miura gravatar image

At the very least, we need to update the humidity_range.data.

First, try to change the humidity_range.data before publish as follows. You should be able to read the data as changed.

 humidity_range.data += 0.1;
 humidity.publish( &humidity_range );
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-11-06 02:04:40 -0500

Seen: 89 times

Last updated: Nov 06 '20