create_wall_timer bind's callback funtion won't work [closed]
HI all:
i am new to ROS2-Foxy, i create a ros2 node class which inherit from rclcpp::Node
as a compoment like this: RCLCPP_COMPONENTS_REGISTER_NODE(utopia::drivers::rtk::SerialNode)
, i decleared a walltime timer in two ways(lamda funtion or not lamda ), when i launch this node, the publisher inside this wall_timer's bind funtion never was called.
- desicreption:
way 1 no lamda:
first : define a timer as class member in Class's header like this : rclcpp::TimerBase::SharedPtr read_timer_;
then: implement timer in my class's constructor like this : `read_timer_ = this->create_wall_timer( 50ms, std::bind(&SerialNode::read_callback, this)); (Result: the callback never have called )
way 2(lamda):
`read_timer_ = create_wall_timer(
50ms, [this](){
printf("read gpgga callback \n");
unsigned char buffer[BUFFER_SIZE] = {0};
int serial_byte_num = serial_.read(buffer, BUFFER_SIZE);
auto message = std_msgs::msg::ByteMultiArray();
gpgga_publisher_->publish(message);
}); `
(**Result: the lamda function never have called also ** )
Is there anything i missed? i also try not to resigist node not as a compoment and wirte a main.cpp
to build an excute node like this: (Still the function that i bind to wall_timer still not be called ):
-----main.cpp----
`int main(int argc, char* argv[]){
rclcpp::init(argc, argv);
rclcpp::NodeOptions options(rclcpp::NodeOptions().use_intra_process_comms(true));
rclcpp::spin(std::make_shared<SerialNode>(options));
rclcpp::shutdown();
return 0;
} `
Anyone can help me , i will be really appreciate !!
On this site you should not ordinarily close a question unless there is some problem. It's fine to answer your own question if you figure it out. What you (the author of the question) should do is click on the checkmark in the gray circle to indicate your approval of an Answer.