contact.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:spqrel_tools 作者: LCAS 项目源码 文件源码
def __init__(self, moduleName):
        # get connection from command line:
        from optparse import OptionParser

        parser = OptionParser()
        parser.add_option("--ip", dest="ip", default="",
                          help="IP/hostname of broker. Default is system's default IP address.", metavar="IP")
        parser.add_option("--port", dest="port", default=0,
                          help="IP/hostname of broker. Default is automatic port.", metavar="PORT")
        parser.add_option("--pip", dest="pip", default="127.0.0.1",
                          help="IP/hostname of parent broker. Default is 127.0.0.1.", metavar="IP")
        parser.add_option("--pport", dest="pport", default=9559,
                          help="port of parent broker. Default is 9559.", metavar="PORT")

        (options, args) = parser.parse_args()
        self.ip = options.ip
        self.port = int(options.port)
        self.pip = options.pip
        self.pport = int(options.pport)
        self.moduleName = moduleName

        self.init_almodule()

        # ROS initialization:
        rospy.init_node('naoqi_tactile')

        # init. messages:
        self.tactile = TactileTouch()              
        self.bumper = Bumper()
        self.tactilePub = rospy.Publisher("tactile_touch", TactileTouch, queue_size=1)
        self.bumperPub = rospy.Publisher("bumper", Bumper, queue_size=1)

        try:
            footContact = self.memProxy.getData("footContact", 0)
        except RuntimeError:
            footContact = None

        if footContact is None:
            self.hasFootContactKey = False
            rospy.loginfo("Foot contact key is not present in ALMemory, will not publish to foot_contact topic.")
        else:
            self.hasFootContactKey = True
            self.footContactPub = rospy.Publisher("foot_contact", Bool, latch=True, queue_size=1)
            self.footContactPub.publish(footContact > 0.0)

        # constants in TactileTouch and Bumper will not be available in callback functions
        # as they are executed in the parent broker context (i.e. on robot),
        # so they have to be copied to member variables
        self.tactileTouchFrontButton = TactileTouch.buttonFront;
        self.tactileTouchMiddleButton = TactileTouch.buttonMiddle;
        self.tactileTouchRearButton = TactileTouch.buttonRear;
        self.bumperRightButton = Bumper.right;
        self.bumperLeftButton = Bumper.left;

        self.subscribe()

        rospy.loginfo("nao_tactile initialized")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号