goroslib_subscriber_test.go 662 B

12345678910111213141516171819202122232425262728293031323334
  1. package test
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "github.com/bluenviron/goroslib/v2"
  5. "log"
  6. "testing"
  7. )
  8. func TestGoroslibSubscriber(t *testing.T) {
  9. // create a node and connect to the master
  10. n, err := goroslib.NewNode(goroslib.NodeConf{
  11. Name: "goroslib_sub",
  12. MasterAddress: "127.0.0.1:11311",
  13. })
  14. if err != nil {
  15. panic(err)
  16. }
  17. defer n.Close()
  18. // create a subscriber
  19. sub, err := goroslib.NewSubscriber(goroslib.SubscriberConf{
  20. Node: n,
  21. Topic: "/cicv_location",
  22. Callback: func(msg *pjisuv_msgs.PerceptionLocalization) {
  23. log.Printf("Incoming: %+v\n", msg)
  24. },
  25. })
  26. if err != nil {
  27. panic(err)
  28. }
  29. defer sub.Close()
  30. }