ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Yes, you can, in principle. However, your code won't work.
I'm not sure which of several problems you want us to ignore, but to at least address the major concerns regarding publishers: You need to create a publisher just once, but once it is created you need to make sure that the publisher stays somewhere and isn't destroyed.