[src] baxter_examples

__init__.py

# Copyright (c) 2013-2015, Rethink Robotics
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
#    this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of the Rethink Robotics nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from .recorder import JointRecorder

recorder.py


# Copyright (c) 2013-2015, Rethink Robotics
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
#    this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of the Rethink Robotics nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import rospy

import baxter_interface

from baxter_interface import CHECK_VERSION

class JointRecorder(object):
    def __init__(self, filename, rate):
        """
        Records joint data to a file at a specified rate.
        """
        self._filename = filename
        self._raw_rate = rate
        self._rate = rospy.Rate(rate)
        self._start_time = rospy.get_time()
        self._done = False

        self._limb_left = baxter_interface.Limb("left")
        self._limb_right = baxter_interface.Limb("right")
        self._gripper_left = baxter_interface.Gripper("left", CHECK_VERSION)
        self._gripper_right = baxter_interface.Gripper("right", CHECK_VERSION)
        self._io_left_lower = baxter_interface.DigitalIO(‘left_lower_button‘)
        self._io_left_upper = baxter_interface.DigitalIO(‘left_upper_button‘)
        self._io_right_lower = baxter_interface.DigitalIO(‘right_lower_button‘)
        self._io_right_upper = baxter_interface.DigitalIO(‘right_upper_button‘)

        # Verify Grippers Have No Errors and are Calibrated
        if self._gripper_left.error():
            self._gripper_left.reset()
        if self._gripper_right.error():
            self._gripper_right.reset()
        if (not self._gripper_left.calibrated() and
            self._gripper_left.type() != ‘custom‘):
            self._gripper_left.calibrate()
        if (not self._gripper_right.calibrated() and
            self._gripper_right.type() != ‘custom‘):
            self._gripper_right.calibrate()

    def _time_stamp(self):
        return rospy.get_time() - self._start_time

    def stop(self):
        """
        Stop recording.
        """
        self._done = True

    def done(self):
        """
        Return whether or not recording is done.
        """
        if rospy.is_shutdown():
            self.stop()
        return self._done

    def record(self):
        """
        Records the current joint positions to a csv file if outputFilename was
        provided at construction this function will record the latest set of
        joint angles in a csv format.

        This function does not test to see if a file exists and will overwrite
        existing files.
        """
        if self._filename:
            joints_left = self._limb_left.joint_names()
            joints_right = self._limb_right.joint_names()
            with open(self._filename, ‘w‘) as f:
                f.write(‘time,‘)
                f.write(‘,‘.join([j for j in joints_left]) + ‘,‘)
                f.write(‘left_gripper,‘)
                f.write(‘,‘.join([j for j in joints_right]) + ‘,‘)
                f.write(‘right_gripper\n‘)

                while not self.done():
                    # Look for gripper button presses
                    if self._io_left_lower.state:
                        self._gripper_left.open()
                    elif self._io_left_upper.state:
                        self._gripper_left.close()
                    if self._io_right_lower.state:
                        self._gripper_right.open()
                    elif self._io_right_upper.state:
                        self._gripper_right.close()
                    angles_left = [self._limb_left.joint_angle(j)
                                   for j in joints_left]
                    angles_right = [self._limb_right.joint_angle(j)
                                    for j in joints_right]

                    f.write("%f," % (self._time_stamp(),))

                    f.write(‘,‘.join([str(x) for x in angles_left]) + ‘,‘)
                    f.write(str(self._gripper_left.position()) + ‘,‘)

                    f.write(‘,‘.join([str(x) for x in angles_right]) + ‘,‘)
                    f.write(str(self._gripper_right.position()) + ‘\n‘)

                    self._rate.sleep()
时间: 2024-10-12 08:58:51

[src] baxter_examples的相关文章

Android的ImageView中的android:src和android:background的区别

http://www.androidren.com/index.php?qa=301&qa_1=android的imageview中的android-src和android-background的区别 有下面几个不同点: 1.src是前景foreground.background是后景background. 2.src是显示内容,background是背景. 3.background是所有view都有的属性,而src是ImageView特有的,它会受到android:scaleType的影响,而

java中获得src路径下文件的常用方法

在代码中一般读取src下的配置文件 读取src路径下的log4j.properties和message.properties 读取message.properties文件并将properties中的键值对转为map PropertiesServlet.class.getClassLoader().getResourceAsStream("/message.properties");返回值是一个InputStream   /**      * 根据java标准properties文件读取

idea项目增加module后,增加的目录(src)无法增加包(Package)

在idea项目中,增肌model后,在项目根目录下增加src目录,右键发现无法增加包(Package). 仔细观察发现,新增加的src目录是棕色,而原先的src目录是浅蓝色的,见下图: 在src右键,new->菜单发现没有Package菜单,见下图: 最后发现,需要将src目录变为:Sources Root,见下图: 点击菜单后,src则可以添加包(Package).

eclipse maven工程中src/main/resources目录下创建的文件夹是包图标的解决方法

如图:在src/main/resources目录下创建的文件夹却以包的图标显示  修改方法: 入下图,按顺序1 ,2,3,4操作,把3处remove,在4处添加**  修改后如下:  然后点击完成后,文件夹图标显示正常了 

Eclipse中的创建maven项目,无法添加src/main/java等source folder

通过Eclipse创建Java Web项目,目录结构如下: 默认是只有src/main/resources 这个source folder 按照maven目录结构,还需要src/main/java ;  src/test/java; src/test/resources 等 在eclipse中创建这些source folder时,会出现下面的情况: 解决如下: 一. 打开Eclipse的Navigator目录,依次创建missing的 source folder即可. 不知道怎么打开的,可以看我

服务器生成大量photo.src文件...

公司的某一台机器中招了,今天我在使用的时候,突然发现我常用的文件夹里都有一个叫photo.src的文件,不太大,2M不到,但是我又到别的几个文件夹都发现了这个同名的文件,这就搞得我心里发毛,于是我就#find / -name photo.src看了一下,好家伙,原来我的挂载盘里每个文件夹(包括子文件夹)都有这么一个文件,这样积少成多,既然吃了我10多个G的磁盘容量,详情见图: 这个photo.scr无疑就是病毒,但是我百度了一圈却没有看到这个问题的解决方法,而且现在看top是正常.不过之前有同事

maven web不能创建src/main/java等文件等问题

我们在创建maven web项目的时候,默认只有src/main/resources这个source folder,我们按照maven结构添加src/main/java和src/test/java等source folder时,会报the folder is already .... 解决办法 建立folder,比如直接建立src/main/java  folder,src/main/java source folder就会显示出来. 原因:右键项目名->build path->configu

编译安装mmseg提示cannot find input file: src/Makefile.in错误

今天安装中文词检索功能模块 coreseek,其中一个分词模块 mmseg ,编译安装到最后,出现annot find input file: src/Makefile.in aclocal   //是一个perl 脚本程序,它的定义是:"aclocal - create aclocal.m4 by scanning configure.ac"libtoolize --force  //运行后有一个错误,不用管它.automake --add-missingautoconfautohe

href和src的使用场景

href和src的使用场景 href和src的用法虽然简单,但是有时候会突然记不起来该怎么用,且两者不可相互替换,下面列出来方便记忆,并给出具体区别. href的使用: 1.外部css引用:<link type="text/css" rel="stylesheet" href="../css/test.css" />   2.<a>标签的使用: <a href="http://www.baidu.com&q