예제 #1
0
    def on_enter(self, userdata):
        # When entering this state, we send the action goal once to let the robot start its work.

        # As documented above, we get the specification of which dishwasher to use as input key.
        # This enables a previous state to make this decision during runtime and provide the ID as its own output key.

        # Create the goal.
        tweet = SendTweetGoal() 
        tweet.text = userdata.tweet_text
        
        if len(userdata.tweet_text) > 140:
            tweet.text = '#LAMoR15 #ECMR15 I just told a too looong joke, stupid tweet length!'

        tweet.with_photo = True
        img = cv2.imread(userdata.picture_path)

        bridge = CvBridge()
        image_message = bridge.cv2_to_imgmsg(img, encoding="bgr8")
        tweet.photo = image_message

        try:
            self._client.send_goal(self._topic, tweet)
        except Exception as e:
                # Since a state failure not necessarily causes a behavior failure, it is recommended to only print warnings, not errors.
                # Using a linebreak before appending the error log enables the operator to collapse details in the GUI.
            Logger.logwarn('Failed to send the TweetPictureState command:\n%s' % str(e))
            self._error = True
예제 #2
0
    def on_enter(self, userdata):
        # When entering this state, we send the action goal once to let the robot start its work.

        # As documented above, we get the specification of which dishwasher to use as input key.
        # This enables a previous state to make this decision during runtime and provide the ID as its own output key.

        # Create the goal.
        tweet = SendTweetGoal()
        tweet.text = userdata.tweet_text

        if len(userdata.tweet_text) > 140:
            tweet.text = '#LAMoR15 #ECMR15 I just told a too looong joke, stupid tweet length!'

        tweet.with_photo = True
        img = cv2.imread(userdata.picture_path)

        bridge = CvBridge()
        image_message = bridge.cv2_to_imgmsg(img, encoding="bgr8")
        tweet.photo = image_message

        try:
            self._client.send_goal(self._topic, tweet)
        except Exception as e:
            # Since a state failure not necessarily causes a behavior failure, it is recommended to only print warnings, not errors.
            # Using a linebreak before appending the error log enables the operator to collapse details in the GUI.
            Logger.logwarn(
                'Failed to send the TweetPictureState command:\n%s' % str(e))
            self._error = True
예제 #3
0
    def execute(self, goal):

        self.image = None
        self.sub = rospy.Subscriber(goal.topic,
                                    Image,
                                    self.image_callback,
                                    queue_size=1)

        # the polling is ugly, but it's hard do do things in a ros-time friendly way otherwise
        while self.image == None and not rospy.is_shutdown(
        ) and not self.server.is_preempt_requested():
            rospy.sleep(0.5)

        result = GrabImageThenTweetResult(success=False)

        if rospy.is_shutdown() or self.server.is_preempt_requested():
            self.server.set_preempted(result)
            return

        # if we got this far we have an image
        tweet = SendTweetGoal(text=goal.text,
                              force=goal.force,
                              with_photo=True,
                              photo=self.image)

        self.tweet_client.send_goal(tweet)

        while not self.tweet_client.wait_for_result(
                rospy.Duration(0.5)) and not rospy.is_shutdown(
                ) and not self.server.is_preempt_requested():
            pass

        if rospy.is_shutdown() or self.server.is_preempt_requested():
            self.server.set_preempted(result)
        else:
            result.success = True
            self.server.set_succeeded(result)