Exemplo n.º 1
0
    public void OnBridgeAvailable(Comm.Bridge bridge)
    {
        Bridge              = bridge;
        Bridge.OnConnected += () =>
        {
            Bridge.AddReader <Ros.Twist>(CMD_VEL_TOPIC, (Ros.Twist msg) =>
            {
                float WHEEL_SEPARATION = 0.515f;
                //float WHEEL_DIAMETER = 0.39273163f;
                float SCALING_RATIO = 0.208f;
                // Assuming that we only get linear in x and angular in z
                double v = msg.linear.x;
                double w = msg.angular.z;

                wheelLeftVel  = SCALING_RATIO * (float)(v - w * 0.5 * WHEEL_SEPARATION);
                wheelRightVel = SCALING_RATIO * (float)(v + w * 0.5 * WHEEL_SEPARATION);
            });

            Bridge.AddService <Ros.Srv.Empty, Ros.Srv.Empty>(CENTER_GRIPPER_SRV, msg =>
            {
                hook.CenterHook();
                return(new Ros.Srv.Empty());
            });

            Bridge.AddService <Ros.Srv.SetBool, Ros.Srv.SetBoolResponse>(ATTACH_GRIPPER_SRV, msg =>
            {
                hook.EngageHook(msg.data);
                return(new Ros.Srv.SetBoolResponse()
                {
                    success = true, message = ""
                });
            });
        };
    }
Exemplo n.º 2
0
    public void OnBridgeAvailable(Comm.Bridge bridge)
    {
        Bridge              = bridge;
        Bridge.OnConnected += () =>
        {
            // tugbot
            Bridge.AddReader <Ros.Twist>(CMD_VEL_TOPIC,
                                         (Ros.Twist msg) =>
            {
                float WHEEL_SEPARATION = 0.515f;
                float WHEEL_DIAMETER   = 0.39273163f;
                float SCALING_RATIO    = 0.208f;
                // Assuming that we only get linear in x and angular in z
                double v = msg.linear.x;
                double w = msg.angular.z;

                wheelLeftVel  = SCALING_RATIO * (float)(v - w * 0.5 * WHEEL_SEPARATION);
                wheelRightVel = SCALING_RATIO * (float)(v + w * 0.5 * WHEEL_SEPARATION);
            });

            Bridge.AddReader <WheelsCmdStampedMsg>(WHEEL_CMD_TOPIC,
                                                   (WheelsCmdStampedMsg msg) =>
            {
                wheelLeftVel  = msg.vel_left;
                wheelRightVel = msg.vel_right;
            });

            // Autoware vehicle command
            Bridge.AddReader <Ros.VehicleCmd>(AUTOWARE_CMD_TOPIC,
                                              (Ros.VehicleCmd msg) =>
            {
                float WHEEL_SEPARATION = 0.1044197f;
                //float WHEEL_DIAMETER = 0.065f;
                float L_GAIN = 0.25f;
                float A_GAIN = 8.0f;
                // Assuming that we only get linear in x and angular in z
                double v = msg.twist_cmd.twist.linear.x;
                double w = msg.twist_cmd.twist.angular.z;

                wheelLeftVel  = (float)(L_GAIN * v - A_GAIN * w * 0.5 * WHEEL_SEPARATION);
                wheelRightVel = (float)(L_GAIN * v + A_GAIN * w * 0.5 * WHEEL_SEPARATION);
            });

            Bridge.AddService <Ros.Srv.Empty, Ros.Srv.Empty>(CENTER_GRIPPER_SRV, msg =>
            {
                hook.CenterHook();
                return(new Ros.Srv.Empty());
            });

            Bridge.AddService <Ros.Srv.SetBool, Ros.Srv.SetBoolResponse>(ATTACH_GRIPPER_SRV, msg =>
            {
                hook.EngageHook(msg.data);
                return(new Ros.Srv.SetBoolResponse()
                {
                    success = true, message = ""
                });
            });

            string override_topic;
            if (Bridge.Version == 1)
            {
                JostickRos1Writer = Bridge.AddWriter <Ros.Joy>(JOYSTICK_ROS1);
                override_topic    = JOYSTICK_OVERRIDE_TOPIC_ROS1;
            }
            else
            {
                override_topic = JOYSTICK_OVERRIDE_TOPIC_ROS2;
            }
            JoystickOverrideTopicWriter = Bridge.AddWriter <BoolStamped>(override_topic);
            Bridge.AddReader <BoolStamped>(override_topic, stamped =>
            {
                ManualControl = stamped.data;
            });

            if (FirstConnection)
            {
                var stamp = new BoolStamped()
                {
                    header = new Ros.Header()
                    {
                        stamp    = Ros.Time.Now(),
                        seq      = seq++,
                        frame_id = "joystick",
                    },
                    data = true,
                };

                var topic = (Bridge.Version == 1) ? JOYSTICK_OVERRIDE_TOPIC_ROS1 : JOYSTICK_OVERRIDE_TOPIC_ROS2;
                JoystickOverrideTopicWriter.Publish(stamp);

                FirstConnection = false;
            }

            ManualControl = true;
        };
    }