Exemple #1
0
        static RosPublisher <Twist> CreatePublisher(IRosbridgeMessageDispatcher messageDispatcher)
        {
            RosPublisher <Twist> publisher = new RosPublisher <Twist>(messageDispatcher, "/turtle1/cmd_vel");

            publisher.AdvertiseAsync();

            return(publisher);
        }
Exemple #2
0
 // Throttles message publishing rate to a defined period, to be used within the Update function
 protected bool Publish <T>(RosPublisher <T> publisher, T data)
     where T : IRosClassInterface, new()
 {
     System.Double currTimeStamp = Time.unscaledTime;
     if (currTimeStamp - prevTimeStamp[publisher.name] > period[publisher.name])
     {
         publisher.SendMessage(data);
         prevTimeStamp[publisher.name] = currTimeStamp;
         return(true);
     }
     return(false);
 }
Exemple #3
0
 protected bool Advertise <T>(string name, string topic, double rate, out RosPublisher <T> publisher)
     where T : IRosClassInterface, new()
 {
     if (prevTimeStamp.ContainsKey(name))
     {
         publisher = default(RosPublisher <T>);
         return(false);
     }
     prevTimeStamp[name] = Time.unscaledDeltaTime;
     period[name]        = 1 / rate;
     publisher           = new RosPublisher <T>(name, topic, 1);
     return(true);
 }
    protected bool Unadvertise <T>(RosPublisher <T> publisher)
        where T : IRosClassInterface, new()
    {
        if (prevTimeStamp.ContainsKey(publisher.name))
        {
            prevTimeStamp.Remove(publisher.name);
            period.Remove(publisher.name);

            publisher.Terminate();
            publisher = null;
            return(true);
        }

        return(false);
    }
Exemple #5
0
 // Start is called before the first frame update
 void Start()
 {
     rosPublisher = GameObject.FindGameObjectWithTag("RosManager").GetComponent <RosPublisher>();
 }