Esempio n. 1
0
def db_write(pub, state):
    """tms_db_writerにトピックを送る(結果、DBにデータを書き込む)
    args:
        pub: node.publisher型。tms_db_writerへのトピック送信用
        state: int型。1なら測定中、0なら測定停止中
    """
    global node, roll, pitch, temp, rate, wave
    now_time = datetime.now().isoformat()

    send_data = {"temp": temp, "rate": rate, "wave": wave}

    db_msg = TmsdbStamped()
    db_msg.header.frame_id = "/world"
    # TODO: db_msgのヘッダーのstampがわからなかったので書いていない
    # clock = Clock()
    # db_msg.header.stamp = clock.now()

    tmp_data = Tmsdb()
    tmp_data.time = now_time
    tmp_data.name = "whs1_mybeat"
    tmp_data.id = 3021
    tmp_data.place = 5001
    tmp_data.sensor = 3021
    tmp_data.state = state
    tmp_data.rr = roll
    tmp_data.rp = pitch
    tmp_data.ry = 0.0

    tmp_data.note = json.dumps(send_data)
    db_msg.tmsdb = [tmp_data]

    pub.publish(db_msg)
Esempio n. 2
0
def main():
    print "Hello World"

    ###init mind wave mobile
    cmd_release = "sudo rfcomm release " + RFCOMM_NUM
    cmd_bind = "sudo rfcomm bind " + RFCOMM_NUM + " " + BT_ADDR
    cmd_chmod = "sudo chmod a+rw /dev/rfcomm" + RFCOMM_NUM
    print cmd_release + "\n", subprocess.check_output(cmd_release.split(" "))
    print cmd_bind + "\n", subprocess.check_output(cmd_bind.split(" "))
    print cmd_chmod + "\n", subprocess.check_output(cmd_chmod.split(" "))
    dev = MindWaveMobile(DEV_PORT)

    ###init ROS
    rospy.init_node('tms_ss_vs_mindwave')
    db_pub = rospy.Publisher('tms_db_data', TmsdbStamped, queue_size=10)
    r = rospy.Rate(1)
    while not rospy.is_shutdown():
        dev.update(
        )  # must update() many times in a loop because most of buffer data is stuff data
        if dev.is_updated:
            r.sleep()
            dev.is_updated = False

            ###make json text
            note_d = {
                "meditation": str(dev.meditation),
                "attention": str(dev.attention),
                "poor_signal": str(dev.poor_signal)
            }
            note_j = json.dumps(note_d)

            ###regist to DB
            msg = TmsdbStamped()
            db = Tmsdb()
            db.time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
            db.name = "mindwavemobile"
            db.id = 3017
            db.sensor = 3017
            db.place = 1001
            db.note = note_j
            msg.tmsdb.append(db)
            msg.header.stamp = rospy.get_rostime() + rospy.Duration(
                9 * 60 * 60)
            db_pub.publish(msg)

            ###show messege
            print "Med:",
            print dev.meditation,
            print "    Att:",
            print dev.attention,
            print "    signal:",
            print dev.poor_signal
Esempio n. 3
0
def main():
    print "Hello World"

    ###init mind wave mobile
    cmd_release =   "sudo rfcomm release "+RFCOMM_NUM
    cmd_bind =      "sudo rfcomm bind "+RFCOMM_NUM+" "+BT_ADDR
    cmd_chmod =     "sudo chmod a+rw /dev/rfcomm"+RFCOMM_NUM
    print cmd_release+"\n", subprocess.check_output(cmd_release.split(" "))
    print cmd_bind+"\n",    subprocess.check_output(cmd_bind.split(" "))
    print cmd_chmod+"\n",   subprocess.check_output(cmd_chmod.split(" "))
    dev = MindWaveMobile(DEV_PORT)

    ###init ROS
    rospy.init_node('tms_ss_vs_mindwave')
    db_pub = rospy.Publisher('tms_db_data', TmsdbStamped, queue_size=10)
    r = rospy.Rate(1)
    while not rospy.is_shutdown():
        dev.update()        # must update() many times in a loop because most of buffer data is stuff data
        if dev.is_updated:
            r.sleep()
            dev.is_updated = False

            ###make json text
            note_d = {"meditation": str(dev.meditation),
                      "attention": str(dev.attention),
                      "poor_signal": str(dev.poor_signal)}
            note_j = json.dumps(note_d)

            ###regist to DB
            msg = TmsdbStamped()
            db = Tmsdb()
            db.time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
            db.name = "mindwavemobile"
            db.id = 3017
            db.sensor = 3017
            db.place = 1001
            db.note = note_j
            msg.tmsdb.append(db)
            msg.header.stamp = rospy.get_rostime()+rospy.Duration(9*60*60)
            db_pub.publish(msg)

            ###show messege
            print "Med:",
            print dev.meditation,
            print "    Att:",
            print dev.attention,
            print "    signal:",
            print dev.poor_signal
Esempio n. 4
0
    def __init__(self):
        moveit_commander.roscpp_initialize(sys.argv)
        rospy.init_node('object_setting')
        rospy.on_shutdown(self.shutdown)

        self.scene_pub = rospy.Publisher('planning_scene', PlanningScene)
        self.colors = dict()

        scene = PlanningSceneInterface()

        rospy.sleep(1)

        temp_dbdata = Tmsdb()
        temp_dbdata.name = 'chipstar_red'

        rospy.wait_for_service('tms_db_reader')
        try:
            tms_db_reader = rospy.ServiceProxy('tms_db_reader', TmsdbGetData)
            res = tms_db_reader(temp_dbdata)
Esempio n. 5
0
    def call_dbwriter(self, msg):
        print 'SleepState -> %s' % (msg)

        note_d = {"sleepstate": str(msg)}
        note_j = json.dumps(note_d)

        msg = TmsdbStamped()
        db = Tmsdb()
        db.time   = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
        db.name   = "nursingcare_bed"
        db.type   = "sensor"
        db.id     = 3020
        db.sensor = 3020
        db.place  = 5001
        db.note   = note_j
        msg.tmsdb.append(db)
        msg.header.stamp = rp.get_rostime() + rp.Duration(9 * 60 * 60)
        self.db_pub.publish(msg)

        return True
Esempio n. 6
0
    def __init__(self):
        moveit_commander.roscpp_initialize(sys.argv)
        rospy.init_node('object_setting')
        rospy.on_shutdown(self.shutdown)

        self.scene_pub = rospy.Publisher('planning_scene', PlanningScene)
        self.colors = dict()

        scene = PlanningSceneInterface()

        rospy.sleep(1)

        temp_dbdata = Tmsdb()
        temp_dbdata.name = 'chipstar_red'

        rospy.wait_for_service('tms_db_reader')
        try:
            tms_db_reader = rospy.ServiceProxy('tms_db_reader', TmsdbGetData)
            res = tms_db_reader(temp_dbdata)
        except rospy.ServiceException, e:
            print "Service call failed: %s"%e
            self.shutdown()
Esempio n. 7
0
    r = rospy.Rate(1)
    while not rospy.is_shutdown():
        r.sleep()
        # ##get heartrate value
        dev.write("G5\r")  # get heartrate buffer[0~4]
        time.sleep(0.5)
        ret = dev.read(dev.inWaiting())
        rate = ret.split(" ")[2]
        print "heartrate:" + rate + "     raw:" + ret
        if int(rate) == 0:
            print "    failed to get heartrate value"
            continue

        # ##make json text
        note_d = {"heartrate": rate}
        # print json.dumps(note_d, indent=4)
        note_j = json.dumps(note_d)

        # ##regist to DB
        msg = TmsdbStamped()
        db = Tmsdb()
        db.time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
        db.name = "heartrate_sensor"
        db.id = 3018
        db.sensor = 3018
        db.place = 1001
        db.note = note_j
        msg.tmsdb.append(db)
        msg.header.stamp = rospy.get_rostime() + rospy.Duration(9 * 60 * 60)
        db_pub.publish(msg)
Esempio n. 8
0
    r = rospy.Rate(1)
    while not rospy.is_shutdown():
        r.sleep()
        # ##get heartrate value
        dev.write("G5\r")  # get heartrate buffer[0~4]
        time.sleep(0.5)
        ret = dev.read(dev.inWaiting())
        rate = ret.split(" ")[2]
        print "heartrate:"+rate+"     raw:"+ret
        if int(rate) == 0:
            print "    failed to get heartrate value"
            continue

        # ##make json text
        note_d = {"heartrate": rate}
        # print json.dumps(note_d, indent=4)
        note_j = json.dumps(note_d)

        # ##regist to DB
        msg = TmsdbStamped()
        db = Tmsdb()
        db.time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
        db.name = "heartrate_sensor"
        db.id = 3018
        db.sensor = 3018
        db.place = 1001
        db.note = note_j
        msg.tmsdb.append(db)
        msg.header.stamp = rospy.get_rostime()+rospy.Duration(9*60*60)
        db_pub.publish(msg)
Esempio n. 9
0
            ###make json text
>>>>>>> 51ecc3540900cfe208d8c2ca1ecaf2184d407ca7
            note_d = {"meditation": str(dev.meditation),
                      "attention": str(dev.attention),
                      "poor_signal": str(dev.poor_signal)}
            note_j = json.dumps(note_d)

<<<<<<< HEAD
            # regist to DB
=======
            ###regist to DB
>>>>>>> 51ecc3540900cfe208d8c2ca1ecaf2184d407ca7
            msg = TmsdbStamped()
            db = Tmsdb()
            db.time = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
            db.name = "mindwavemobile"
            db.id = 3017
            db.sensor = 3017
            db.place = 1001
            db.note = note_j
            msg.tmsdb.append(db)
<<<<<<< HEAD
            msg.header.stamp = rospy.get_rostime() + rospy.Duration(9 * 60 * 60)
            db_pub.publish(msg)

            # show messege
=======
            msg.header.stamp = rospy.get_rostime()+rospy.Duration(9*60*60)
            db_pub.publish(msg)

            ###show messege