Ejemplo n.º 1
0
def main():
  rospy.init_node('csvout_cync_inhand_node')

  while(True):
    input_data = raw_input("input interval range(0,50): ")
    if 0 < float(input_data) < 50:
      interval = float(input_data)
      print("interval sets ", interval)
      break
    elif input_data == "q":
      print("exit")
      rospy.signal_shutdown('finish')
    else:
      print("ERROR: invalid value")

  # storing = Storing_dydata()
  # mycsv_l = CSVoutput("thick_l(000).csv")
  runvel = 0.01
  file_name = "test" + str(interval) + "-" + str(runvel) + "_"
  msg_list = [["/dynamixel_param/", dynamixel_param_msg()], ["/fingervision/fv_filter1_objinfo/", Filter1ObjInfo()], ["/dynamixel_data/", dynamixel_msg()]]
  mycsv = CSVoutput(file_name, msg_list)

  # start_record_client("l")
  # start_record_client("r")

  # print "start record!"

  #subscribe設定
  sub_fv_filtered1_objinfo = Subscribe("Filter1ObjInfo")
  sub_dynamixel_data = Subscribe("dynamixel_data")
  rospy.sleep(0.5)
  rospy.Subscriber("/dynamixel_param", dynamixel_param_msg, lambda msg:mycsv.Storing([msg, sub_fv_filtered1_objinfo.req, sub_dynamixel_data.req]))

  # set_interval_client(interval)
  Go2itv_client(interval, runvel)

  time_start = time.time()

  print "ready OK!"

  # while True:
  #   s = raw_input('type "q" to finish: ')
  #   print s=="q"
  #   if s=="q":
  #     mycsv.Write()
  #     # stop_record_client("l")
  #     # stop_record_client("r")
  #     break
  
  while True:
    if time.time()-time_start > 20:
      mycsv.Write()
      break
    rospy.sleep(0.01)

  set_interval_client(16.0)

  rospy.signal_shutdown('finish')
  rospy.spin()
Ejemplo n.º 2
0
class Updater:
    def __init__(self):
        self.load_config() 
        self.anime = Anime(self.cache_dir)
        self.downloader = Subscribe(self.list_path, self.cache_dir, self.aria2_url, self.aria2_dir)

    def load_config(self):
        self.main_dir = os.path.abspath(os.path.dirname(__file__))
        try: 
            with open(os.path.join(self.main_dir,"config.json"), 'r',  encoding='utf8') as f:
                config = json.load(f)

            self.log_dir = path_format(config["log_dir"])
            if not os.path.isdir(self.log_dir):
                raise Exception("log dir not exist!") 

            # aria2 parameter
            self.aria2_dir = path_format(config["download_dir"])
            self.aria2_url = config["aria2"]

            # two log files
            self.error_log = self.log_dir + "error.log"
            self.update_log = self.log_dir + "update.log"
            logs._init(self.error_log, self.update_log)

            # list file path
            self.list_path = self.log_dir + "mylist.json"
            if not os.path.isfile(self.list_path):
                raise Exception("list.json not exist!")

            # cache dir path: ./log/cache/
            self.cache_dir = self.log_dir + "cache/"
            if not os.path.isdir(self.cache_dir):
                os.makedirs(self.cache_dir)

        except Exception as e:
            print("[error] init: {}".format(e))
            os._exit(1)

    def update(self):
        self.anime.update()

    def download(self):
        self.downloader.download() 
Ejemplo n.º 3
0
def addsub():
    data =json.loads(request.data)
    # print(data)
    Subscribe().subscribe(data['subemail'], data['events'])
    return jsonify("nothing")
Ejemplo n.º 4
0
#! /usr/bin/python3
'''
@Author: Shuying Li <*****@*****.**>
@Date: 2020-02-14 16:16:53
@LastEditTime: 2020-06-28 12:42:03
@LastEditors: Shuying Li <*****@*****.**>
@Description: 
@FilePath: /v2ray_cli/v2ray_cli.py
'''

import os
import configparser
from subscribe import Subscribe

cfg_pathname = "./cfg.conf"
json_template_pathname = "./config.json.template"

if __name__ == "__main__":
    cfg = configparser.ConfigParser()
    cfg.read(cfg_pathname, encoding='UTF-8')

    if cfg["subscribe"]["url"] == "":
        url = input("Please Enter The Subscription Address: ")
        cfg["subscribe"] = {"url": url}
        with open(cfg_pathname, 'w') as cfg_file:
            cfg.write(cfg_file)
    else:
        url = cfg["subscribe"]["url"]

    sub = Subscribe(url, json_template_pathname)
Ejemplo n.º 5
0
 def __init__(self):
     self.load_config() 
     self.anime = Anime(self.cache_dir)
     self.downloader = Subscribe(self.list_path, self.cache_dir, self.aria2_url, self.aria2_dir)
Ejemplo n.º 6
0
from rub import Rubbing, PID
import yaml
from subscribe import Subscribe
from inhand_statemachine_util import Inhand
# from inhand_util import Inhand

file_name = "/home/suzuki/ros_ws/ay_tools/fingervision/suzuki/rubbing_hand/scripts/init_pos.yaml"

#ROSのpublisher設定
data_pub = rospy.Publisher("dynamixel_data", dynamixel_msg, queue_size=1)
param_pub = rospy.Publisher("dynamixel_param",
                            dynamixel_param_msg,
                            queue_size=1)

#subscribe設定
sub_fv_prox = Subscribe("ProxVision")
sub_fv_filtered1_objinfo = Subscribe("Filter1ObjInfo")
sub_fv_smaf = Subscribe("fv_smaf")

#Setup the device
DXL_ID = [1, 2, 3, 4]  #Note: value and
# BAUDRATE= 57600
# BAUDRATE= 115200
BAUDRATE = 2e6
DXL_TYPE = 'XM430-W350'
dev = '/dev/ttyUSB0'
dxl = [
    TDynamixel1(DXL_TYPE, dev),
    TDynamixel1(DXL_TYPE, dev),
    TDynamixel1(DXL_TYPE, dev),
    TDynamixel1(DXL_TYPE, dev)
Ejemplo n.º 7
0
 def __init__(self, client):
     """Just remember who created this."""
     self.client = client
     self.sub = Subscribe()
Ejemplo n.º 8
0
class CommandHandler(object):
    implements(IMessageHandlersProvider, IPresenceHandlersProvider)
    
    def __init__(self, client):
        """Just remember who created this."""
        self.client = client
        self.sub = Subscribe()

    
    def get_message_handlers(self):
        return [
            ("normal", self.message),
            ]
            
    def get_presence_handlers(self):
        """Return list of (presence_type, presence_handler) tuples.

        The handlers returned will be called when matching presence stanza is
        received in a client session."""
        return [
            (None, self.presence),
            ("unavailable", self.presence),
            ("subscribe", self.presence_control),
            ("subscribed", self.presence_control),
            ("unsubscribe", self.presence_control),
            ("unsubscribed", self.presence_control),
            ]
    
    def message(self,stanza):
        subject=stanza.get_subject()
        body=stanza.get_body()
        t=stanza.get_type()
        print u'Message from %s received.' % (unicode(stanza.get_from(),)),
        if subject:
            print u'Subject: "%s".' % (subject,),
        if body:
            print u'Body: "%s".' % (body,),
        if t:
            print u'Type: "%s".' % (t,)
        else:
            print u'Type: "normal".'
        if stanza.get_type()=="headline":
            # 'headline' messages should never be replied to
            return True
        if subject:
            subject=u"Re: "+subject
            
        # run command
        # todo: 只进队列让worker线程处理,不回复;因为是同步阻塞IO模型
        body = self.run(unicode(stanza.get_from(),), body)
        
        m=Message(
            to_jid=stanza.get_from(),
            from_jid=stanza.get_to(),
            stanza_type=stanza.get_type(),
            subject=subject,
            body=body)
        if body:
            p = Presence(status=body)
            return [m, p]
        return m
    
    def presence(self,stanza):
        """Handle 'available' (without 'type') and 'unavailable' <presence/>."""
        msg=u"%s has become " % (stanza.get_from())
        t=stanza.get_type()
        if t=="unavailable":
            msg+=u"unavailable"
        else:
            msg+=u"available"

        show=stanza.get_show()
        if show:
            msg+=u"(%s)" % (show,)

        status=stanza.get_status()
        if status:
            msg+=u": "+status
        print msg

    def presence_control(self,stanza):
        """Handle subscription control <presence/> stanzas -- acknowledge
        them."""
        msg=unicode(stanza.get_from())
        t=stanza.get_type()
        if t=="subscribe":
            msg+=u" has requested presence subscription."
        elif t=="subscribed":
            msg+=u" has accepted our presence subscription request."
        elif t=="unsubscribe":
            msg+=u" has canceled his subscription of our."
        elif t=="unsubscribed":
            msg+=u" has canceled our subscription of his presence."

        print msg

        return stanza.make_accept_response()
    
    def run(self, from_jid, cmd):
        gtalk = from_jid[:from_jid.find('/')]
        matches = re.match('^add\s+(.+?)$(?i)', cmd)
        if(matches):
            return self.sub.add(gtalk, matches.group(1))
        
        matches = re.match('^delete\s+(.+?)$(?i)', cmd)
        if(matches):
            return self.sub.delete(gtalk, matches.group(1))

        matches = re.match('^list$(?i)', cmd)
        if(matches):
            return self.sub.list(gtalk)
        
        return self.sub.default(gtalk)