using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ROS2;

public class PublishColorSensor : MonoBehaviour
{

    public GetSumRed SensorValue;
    public string TopicName = "rt/redsensor";

    private ROS2UnityComponent ros2Unity;
    private ROS2Node ros2Node;
    private IPublisher<std_msgs.msg.Float32> chatter_pub;

    // Start is called before the first frame update
    void Start()
    {
        ros2Unity = GetComponent<ROS2UnityComponent>();

        if (ros2Unity.Ok())
        {
            if (ros2Node == null)
            {
                ros2Node = ros2Unity.CreateNode("ROS2LFRcolor");
                chatter_pub = ros2Node.CreatePublisher<std_msgs.msg.Float32>(TopicName);
            }
        }
    }

    void FixedUpdate()
    {
        std_msgs.msg.Float32 msg = new std_msgs.msg.Float32();
        msg.Data = SensorValue.TotalRed;
        chatter_pub.Publish(msg);
    }
}
