Пример #1
0
    def pub_command(self, duration, options):
        self.command_flag = False
        data = adapter_msgs.Adapter()
        data.resource.id = unique_id.toMsg(unique_id.fromRandom())
        data.command_duration = int(duration)
        data.command = options

        print data

        time.sleep(1)
        self.command_pub.publish(data)
Пример #2
0
    def pub_resource_alloc(self, uri, options):
        print 'uri: ', uri, ' options: ', options
        self.resource_alloc_flag = False
        data = adapter_msgs.Adapter()
        data.resource.id = unique_id.toMsg(unique_id.fromRandom())
        data.resource.uri = uri
        data.resource.rapp = self.rapp_parse(uri)
        data.command = options

        print data

        time.sleep(1)
        self.resource_alloc_pub.publish(data)
Пример #3
0
    def resources_alloc_request_callback(self, msg):
        '''
          For allocating a resource, this method is invoked by receiving a topic from bpel service
          @param msg: incoming message
          @type msg: adapter_msgs.Adapter
        '''
        result = False
        # send a request
        rospy.loginfo("AdapterSvc : send request by topic")
        data = adapter_msgs.Adapter()
        data.resource.id = unique_id.toMsg(unique_id.fromRandom())
        data.resource.uri = msg.resource.uri
        data.resource.rapp = msg.resource.rapp

        self.command = msg.command
        self.command_duration = msg.command_duration
        data.command = self.command
        data.command_duration = self.command_duration

        resource_request_id = self.requester.new_request([data.resource])

        self.pending_requests.append(resource_request_id)
        self.requester.send_requests()
        timeout_time = time.time() + self.allocation_timeout

        while not rospy.is_shutdown() and time.time() < timeout_time:
            if resource_request_id in self.pending_requests:
                self.allocated_requests[msg.resource.uri] = resource_request_id
                result = True
                break
            rospy.rostime.wallsleep(0.1)

        if result == False:
            rospy.logwarn(
                "AdapterSvc : couldn't capture required resource [timed out][%s]"
                % msg.resource.uri)
            self.requester.rset[resource_request_id].cancel()
        else:
            rospy.loginfo(
                "AdapterSvc : captured resouce [%s][%s]" %
                (msg.resource.uri, self.allocated_requests[msg.resource.uri]))
Пример #4
0
    def command_request_callback(self, msg):
        '''
          Called by Subscriber when the command arrived from the server
          This method control the turtlebot according to the command
          @param msg : incoming message
          @type msg: adapter_msgs.Adapter
        '''
        topic_name = "/turtlebot/android/virtual_joystick/cmd_vel"
        publisher = rospy.Publisher(topic_name, Twist)

        data = adapter_msgs.Adapter()

        command = msg.command
        command_duration = msg.command_duration

        print "=================================================="
        rospy.loginfo(
            "command_request_callback : ready to send cmd_vel to turtlebot")
        rospy.loginfo("command_request_callback : command = %s", command)
        print "=================================================="
        twist = Twist()

        if command == 'forward':
            print 'in forward'
            twist.linear.x = 0.1
            twist.linear.y = 0
            twist.linear.z = 0
            twist.angular.x = 0
            twist.angular.y = 0
            twist.angular.z = 0

        elif command == 'backward':
            print 'in backward'
            twist.linear.x = -0.1
            twist.linear.y = 0
            twist.linear.z = 0
            twist.angular.x = 0
            twist.angular.y = 0
            twist.angular.z = 0

        elif command == 'cycle_left':
            print 'left'
            twist.linear.x = 0
            twist.linear.y = 0
            twist.linear.z = 0
            twist.angular.x = 0
            twist.angular.y = 0
            twist.angular.z = 1

        elif command == 'cycle_right':
            print 'right'
            twist.linear.x = 0
            twist.linear.y = 0
            twist.linear.z = 0
            twist.angular.x = 0
            twist.angular.y = 0
            twist.angular.z = -1

        print "=================================================="
        rospy.loginfo("command_request_callback : command value : ")
        print command
        rospy.loginfo("command_request_callback : command duration value : ")
        print command_duration
        rospy.loginfo("command_request_callback : published twist value : ")
        print twist

        r = rospy.Rate(10)
        stop_time = time.time() + command_duration

        # Publish Twist!
        while time.time() < stop_time:
            publisher.publish(twist)
            r.sleep()

        print "=================================================="
        command_reply_publisher = rospy.Publisher(
            '/services/adapter/command_reply', std_msgs.String)
        time.sleep(1)
        command_reply_publisher.publish("command_success")