Exemplo n.º 1
0
func main() {
	node := ros.NewNode("/listener")
	defer node.Shutdown()
	node.Logger().SetSeverity(ros.LogLevelDebug)
	node.NewSubscriber("/chatter", rosgo_tests.MsgHello, callback)
	node.Spin()
}
Exemplo n.º 2
0
func main() {
	node := ros.NewNode("/test_param")
	defer node.Shutdown()

	if hasParam, err := node.HasParam("/rosdistro"); err != nil {
		log.Fatal(err)
	} else {
		if !hasParam {
			log.Fatal("HasParam() failed.")
		}
	}

	if foundKey, err := node.SearchParam("/rosdistro"); err != nil {
		log.Fatal(err)
	} else {
		if foundKey != "/rosdistro" {
			log.Fatal("SearchParam() failed.")
		}
	}

	if param, err := node.GetParam("/rosdistro"); err != nil {
		log.Fatal(err)
	} else {
		if value, ok := param.(string); !ok {
			log.Fatal("GetParam() failed.")
		} else {
			if value != "groovy\n" {
				log.Fatalf("Expected 'groovy\\n' but '%s'", value)
			}
		}
	}

	if err := node.SetParam("/test_param", 42); err != nil {
		log.Fatal(err)
	}

	if param, err := node.GetParam("/test_param"); err != nil {
		log.Fatal(err)
	} else {
		if value, ok := param.(int32); ok {
			if value != 42 {
				log.Fatalf("Expected 42 but %d", value)
			}
		} else {
			log.Fatal("GetParam('/test_param') failed.")
		}
	}

	if err := node.DeleteParam("/test_param"); err != nil {
		log.Fatal(err)
	}

	log.Print("Success")
}
Exemplo n.º 3
0
func main() {
	node := ros.NewNode("server")
	defer node.Shutdown()
	logger := node.Logger()
	logger.SetSeverity(ros.LogLevelDebug)
	server := node.NewServiceServer("/add_two_ints", rosgo_tests.SrvAddTwoInts, callback)
	if server == nil {
		fmt.Println("Failed to initialize '/add_two_ints' service server")
		os.Exit(1)
	}
	defer server.Shutdown()
	node.Spin()
}
Exemplo n.º 4
0
func main() {
	node := ros.NewNode("/talker")
	defer node.Shutdown()
	node.Logger().SetSeverity(ros.LogLevelDebug)
	pub := node.NewPublisherWithCallbacks("/chatter", rosgo_tests.MsgHello, onConnect, onDisconnect)

	for node.OK() {
		node.SpinOnce()
		var msg rosgo_tests.Hello
		msg.Data = fmt.Sprintf("hello %s", time.Now().String())
		fmt.Println(msg.Data)
		pub.Publish(&msg)
		time.Sleep(time.Second)
	}
}
Exemplo n.º 5
0
func main() {
	if len(os.Args) != 3 {
		fmt.Print("USAGE: test_client <int> <int>")
		os.Exit(1)
	}

	node := ros.NewNode("client")
	defer node.Shutdown()
	logger := node.Logger()
	logger.SetSeverity(ros.LogLevelDebug)
	cli := node.NewServiceClient("/add_two_ints", rosgo_tests.SrvAddTwoInts)
	defer cli.Shutdown()
	var err error
	var a, b int64
	a, err = strconv.ParseInt(os.Args[1], 10, 32)
	if err != nil {
		fmt.Print(err)
		fmt.Println()
		os.Exit(1)
	}
	b, err = strconv.ParseInt(os.Args[2], 10, 32)
	if err != nil {
		fmt.Print(err)
		fmt.Println()
		os.Exit(1)
	}
	var srv rosgo_tests.AddTwoInts
	srv.Request.A = int32(a)
	srv.Request.B = int32(b)
	if err := cli.Call(&srv); err != nil {
		fmt.Print(err)
		fmt.Println()
	} else {
		fmt.Printf("%d + %d = %d",
			srv.Request.A, srv.Request.B, srv.Response.Sum)
		fmt.Println()
	}
}