def test_dictionary_with_duration(self):
     from std_msgs.msg import Duration
     duration = rospy.rostime.Duration(33, 25)
     expected_message = Duration(data=duration)
     dictionary = {'data': {'secs': duration.secs, 'nsecs': duration.nsecs}}
     message = message_converter.convert_dictionary_to_ros_message(
         'std_msgs/Duration', dictionary)
     self.assertEqual(message, expected_message)
def create_objective():
    bag = rosbag.Bag('./objective.bag', 'w')

    topic = '/agent/objective/period'

    msg = Duration()
    msg.data.secs = 86400  # 24 hours

    bag.write(topic, msg)
    bag.close()
예제 #3
0
 def test_ros_message_with_duration(self):
     from std_msgs.msg import Duration
     duration = rospy.rostime.Duration(33, 25)
     expected_dictionary = {
         'data': {
             'secs'  : duration.secs,
             'nsecs' : duration.nsecs
         }
     }
     message = Duration(data=duration)
     message = serialize_deserialize(message)
     dictionary = message_converter.convert_ros_message_to_dictionary(message)
     self.assertEqual(dictionary, expected_dictionary)
예제 #4
0
    def sub_cone(self, msg):
        header_age = rospy.rostime.Time.now() - msg.header.stamp
        self.pub_delay.publish(Duration(header_age))

        cmd = AckermannDriveStamped()

        if msg.objects:
            cone = msg.objects[0]
            cmd.drive.steering_angle = self.gain_angle * cone.center.x
            cmd.drive.speed = self.gain_speed * (cone.size.x -
                                                 self.target_dist)
        else:
            # no cone
            pass

        self.pub.publish(cmd)
    def __init__(self):
        rospy.init_node('test')
        # worldFrame = rospy.get_param("~worldFrame", "/world")      
        self.msg = Hover()
        self.twist_msg = Twist()
        self.duration_msg = Duration()
        self.hz = 100 # if not set to 100, will not broadcast
        self.rate = rospy.Rate(self.hz)

        # rospy.wait_for_service('/crazyflie/takeoff')
        # self.takeoff_command = rospy.ServiceProxy('/crazyflie/takeoff', Takeoff)

        self.pub_twist = rospy.Publisher('crazyflie/cmd_vel', Twist, queue_size=0)

        rospy.wait_for_service('/vicon/grab_vicon_pose')
        self.pose_getter = rospy.ServiceProxy('/vicon/grab_vicon_pose', viconGrabPose)
 def post(self):
     """request example:
        $ curl -H "Content-type: application/json" \
               -X POST https://0.0.0.0:8888/ \
               -d '{"duration": 86400}'
     """
     rospy.loginfo('Composer request for: ' + str(request.get_json()))
     bag_name = tmp_dir + '/objective-' + next(
         tempfile._get_candidate_names()) + '.bag'
     with rosbag.Bag(bag_name, 'w') as bag:
         duration = Duration()
         duration.data.secs = int(request.get_json()['duration'])
         bag.write('/agent/objective/duration', duration)
     with shelve.open(per_dir + '/storage.shelve') as db:
         db['composed'] += 1
     rospy.loginfo('Bag: ' + bag_name)
     objective_hash = ipfs.add(bag_name)[0]['Hash']
     rospy.loginfo('Objective: ' + objective_hash)
     return jsonify({'objective': objective_hash})
    def echoMessageCallback(self, msg):
        if not self.initialized:
            self.initialized = True
            self.lastPayloadIncreaseTime = rospy.Time.now()

        if (rospy.Time.now() - self.lastPayloadIncreaseTime >
                PAYLOAD_TIMESTEP):
            self.lastPayloadIncreaseTime = rospy.Time.now()
            self.payloadSize *= 2
            rospy.loginfo("Increasing payload size to " +
                          str(self.payloadSize))

        self.echoMessage.data = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(self.payloadSize))
        self.echoMessage.header.stamp = rospy.Time.now()
        delay = msg.header.stamp - self.lastTime
        self.delayPub.publish(Duration(delay))
        self.dataPub.publish(self.echoMessage)
        self.lastTime = msg.header.stamp

        if self.payloadSize > 100:
            rospy.signal_shutdown("finished")
예제 #8
0
def print_time(event):
    uptime = Duration()
    uptime.data = event.current_real - start_time
    rospy.logdebug("Runtime has reached: " + str(int(uptime.data.secs / 60)) +
                   " minutes.")
예제 #9
0
def publish_time(event):
    uptime = Duration()
    uptime.data = event.current_real - start_time
    pub_uptime.publish(uptime)
예제 #10
0
    def create_transport_order(self, _task_id: str, _from_id: str,
                               _to_id: str) -> str:
        """Overrides FormalParserInterface.create_transport_order()"""

        logger.info("ROS create_transport_order")
        service_topic_add_transport_order = self._create_topic(
            self.robot_id, TOPIC_ADD_TRANSPORT_ORDER)
        rospy.wait_for_service(service_topic_add_transport_order)
        try:
            ros_task_id = Id(_task_id, IdType.ID_TYPE_STRING_UUID)
            ros_from_id = Id(_from_id, IdType.ID_TYPE_STRING_NAME)
            ros_to_id = Id(_to_id, IdType.ID_TYPE_STRING_NAME)
            duration = Duration()
            duration.data.secs = DST_RESERVATION_TIME

            # FROM
            move_order_from = MoveOrder(
                move_order_id=ros_task_id.to_msg(),
                destination_entity=TopologyEntity(
                    id=ros_from_id.to_msg(),
                    entity_type=TopologyEntityType(10)),
                destination_reservation_time=duration.data)
            robot_action_load = RobotAction(
                category=ROBOT_ACTION.CATEGORY_MANUAL_LOAD, description="load")

            transport_order_step_from = TransportOrderStep(
                transport_order_step_id=ros_task_id.to_msg(),
                move_order=move_order_from,
                robot_action=robot_action_load)

            # TO
            ros_move_order_to = MoveOrder(
                move_order_id=ros_task_id.to_msg(),
                destination_entity=TopologyEntity(
                    id=ros_to_id.to_msg(), entity_type=TopologyEntityType(10)),
                destination_reservation_time=duration.data)

            ros_robot_action_unload = RobotAction(
                category=ROBOT_ACTION.CATEGORY_MANUAL_UNLOAD,
                description="_UNload")
            ros_transport_order_step_to = TransportOrderStep(
                transport_order_step_id=ros_task_id.to_msg(),
                move_order=ros_move_order_to,
                robot_action=ros_robot_action_unload)

            ros_transport_order = TransportOrder(
                transport_order_id=ros_task_id.to_msg(),
                start_step=transport_order_step_from,
                destination_step=ros_transport_order_step_to)

            add_transport_order_srv_req = rospy.ServiceProxy(
                service_topic_add_transport_order, AddTransportOrder)
            add_transport_order_req = AddTransportOrderRequest(
                transport_order=ros_transport_order)

            ros_service_call_result = add_transport_order_srv_req(
                ros_transport_order)
            self.status = ros_service_call_result.result.result
            logger.info("addTransportOrderResult: %s", str(self.status))

        except rospy.ServiceException as err:
            logger.error("ROS Service (AddTransportOrder) call failed: %s",
                         err)

        except Exception as ex:
            logger.info("ROS Exception: %s", ex)
# -*- coding: utf-8 -*-

import rospy
import rosbag
from std_msgs.msg import String, Duration

bag = rosbag.Bag('./objective.bag', 'w')
msg = Duration(data=rospy.Duration(24 * 60 * 60))

try:
    bag.write('/duration', msg)
finally:
    bag.close()
예제 #12
0
# -*- coding: utf-8 -*-

import rosbag, rospy
from std_msgs.msg import Bool, String, Duration

days_to_sec = lambda days: days*24*60*60

data = { # key - topic, value - message
        '/virtual': Bool(data=True),
        '/expiration': Duration(data=rospy.Duration(days_to_sec(31))),
        '/sensors': String(data='Temperature, pH, Dissolved Oxygen, Conductivity'),
        '/waypoints': String(data='QmcS1uxwzxvQmoMbNZRdKxTShU4wBm97NKYFxKeQxmFJTy')
        }

with rosbag.Bag('./objective.bag', 'w') as bag:
    for topic, msg in data.items():
        bag.write(topic, msg)