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

rosserial subscriber callback is not getting triggered ?

asked 2022-02-11 01:41:31 -0600

Shiva_uchiha gravatar image

updated 2022-02-11 02:31:39 -0600

I am able to see the subscriber subscribed to my topic in my pc. However when I try to publish data , I am not seeing any callback called in micro controller side. Below is my code

#include <mainpp.h>
#include <ros.h>
//#include <geometry_msgs/Twist.h>
#include <std_msgs/String.h>
#include <std_msgs/Float64.h>
#include <geometry_msgs/Twist.h>
#include <nav_msgs/Odometry.h>
#include "imu.h"
#include "data.h"


//void messageCb(const std_msgs::Float64& msg);

void messageCb(const nav_msgs::Odometry& msg);

ros::NodeHandle nh;

std_msgs::String str_msg;
geometry_msgs::Twist roscmd;
nav_msgs::Odometry stats;
extern union union_main sample_outdata;
extern volatile struct imu_akf imu_stat ;
ros::Publisher chatter("cmd_vel", &roscmd);
//ros::Subscriber listener ("odom",&stats);
char hello[] = "Hello world!";



//def quaternion_to_euler(orientation_q):
//    (x, y, z, w) = (orientation_q.x,orientation_q.y,orientation_q.z,orientation_q.w)
//    t0 = +2.0 * (w * x + y * z)
//    t1 = +1.0 - 2.0 * (x * x + y * y)
//    roll = math.atan2(t0, t1)
//    t2 = +2.0 * (w * y - z * x)
//    t2 = +1.0 if t2 > +1.0 else t2
//    t2 = -1.0 if t2 < -1.0 else t2
//    pitch = math.asin(t2)
//    t3 = +2.0 * (w * z + x * y)
//    t4 = +1.0 - 2.0 * (y * y + z * z)

/

/    yaw = math.atan2(t3, t4)
//    return [yaw, pitch, roll]


ros::Subscriber<nav_msgs::Odometry> sub("odom", &messageCb);




void messageCb(const nav_msgs::Odometry& stats)
{


HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);


    // blink the led
//  sample_outdata.realsense_data.translation_x =  stats.pose.pose.position.x;
//  sample_outdata.realsense_data.translation_y =  stats.pose.pose.position.y;
//  float t3 = +2.0 * ((stats.pose.pose.orientation.w * stats.pose.pose.orientation.z) + (stats.pose.pose.orientation.x * stats.pose.pose.orientation.y));
//  float t4 = +1.0 - 2.0 * ((stats.pose.pose.orientation.y * stats.pose.pose.orientation.y )+ (stats.pose.pose.orientation.z * 

stats.pose.pose.orientation.z));
    //  imu_stat.yaw.f 

= atan2(t3, t4);
//  if(msg.data > 1.0)
//  {
//      HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
    //  }
    }

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){
  nh.getHardware()->flush();
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
  nh.getHardware()->reset_rbuf();
}

void setup(void)
{
  nh.initNode();
  nh.advertise(chatter);
  nh.subscribe(sub);
}

    void loop(void)
    {

  chatter.publish(&roscmd);
  nh.spinOnce();

}

I get the following error in terminal image description

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-11 06:39:54 -0600

Shiva_uchiha gravatar image

This issue resolved once, I increased buffer size in nodehandle.h and hardware.h

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-02-11 01:41:31 -0600

Seen: 190 times

Last updated: Feb 11 '22