package main

import (
	"github.com/bluenviron/goroslib/v2"
	"github.com/bluenviron/goroslib/v2/pkg/msgs/std_msgs"
	"log/slog"
	"os"
	"time"
)

/*
2024.5 已经被孙亚伦的队名发送程序替代，此程序仅作为初期测试使用
*/
func main() {
	RosNode, err := goroslib.NewNode(goroslib.NodeConf{
		Name:          "competitionNode",
		MasterAddress: "127.0.0.1:11311",
	})
	rosPublisher, err := goroslib.NewPublisher(goroslib.PublisherConf{
		Node:  RosNode,
		Topic: "/cicv_competition",
		Msg:   &std_msgs.String{}, // msg必须是指针
	})
	if err != nil {
		slog.Error("程序崩溃，创建ros发布者competition失败：", err)
		os.Exit(-1)
	} else {
		slog.Info("创建ros发布者competition成功：")
	}
	for {
		time.Sleep(time.Duration(1) * time.Second)
		// 下发数据
		rosPublisher.Write(&std_msgs.String{
			Data: "cicv测试队名",
		})
		slog.Info("发送数据 cicv测试队名 成功")
	}
}
