idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
233,500 | def _publish ( self , obj ) : bin_obj = umsgpack . packb ( obj ) self . pub . send ( bin_obj ) | Publish the OC object . |
233,501 | def _handshake ( self , conn , addr ) : msg = conn . recv ( len ( MAGIC_REQ ) ) log . debug ( 'Received message %s from %s' , msg , addr ) if msg != MAGIC_REQ : log . warning ( '%s is not a valid REQ message from %s' , msg , addr ) return log . debug ( 'Sending the private key' ) conn . send ( self . __key ) log . debu... | Ensures that the client receives the AES key . |
233,502 | def keep_alive ( self , conn ) : while self . __up : msg = conn . recv ( len ( AUTH_KEEP_ALIVE ) ) if msg != AUTH_KEEP_ALIVE : log . error ( 'Received something other than %s' , AUTH_KEEP_ALIVE ) conn . close ( ) return try : conn . send ( AUTH_KEEP_ALIVE_ACK ) except ( IOError , socket . error ) as err : log . error (... | Maintains auth sessions |
233,503 | def verify_cert ( self ) : log . debug ( 'Verifying the %s certificate, keyfile: %s' , self . certificate , self . keyfile ) try : ssl . create_default_context ( ) . load_cert_chain ( self . certificate , keyfile = self . keyfile ) except ssl . SSLError : error_string = 'SSL certificate and key do not match' log . erro... | Checks that the provided cert and key are valid and usable |
233,504 | def _create_skt ( self ) : log . debug ( 'Creating the auth socket' ) if ':' in self . auth_address : self . socket = socket . socket ( socket . AF_INET6 , socket . SOCK_STREAM ) else : self . socket = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) try : self . socket . bind ( ( self . auth_address , self ... | Create the authentication socket . |
233,505 | def start ( self ) : log . debug ( 'Starting the auth process' ) self . verify_cert ( ) self . _create_skt ( ) log . debug ( 'The auth process can receive at most %d parallel connections' , AUTH_MAX_CONN ) self . socket . listen ( AUTH_MAX_CONN ) thread = threading . Thread ( target = self . _suicide_when_without_paren... | Listen to auth requests and send the AES key . Each client connection starts a new thread . |
233,506 | def stop ( self ) : log . info ( 'Stopping auth process' ) self . __up = False self . socket . close ( ) | Stop the auth proc . |
233,507 | def start ( self ) : log . debug ( 'Creating the consumer using the bootstrap servers: %s and the group ID: %s' , self . bootstrap_servers , self . group_id ) try : self . consumer = kafka . KafkaConsumer ( bootstrap_servers = self . bootstrap_servers , group_id = self . group_id ) except kafka . errors . NoBrokersAvai... | Startup the kafka consumer . |
233,508 | def stop ( self ) : log . info ( 'Stopping te kafka listener class' ) self . consumer . unsubscribe ( ) self . consumer . close ( ) | Shutdown kafka consumer . |
233,509 | def get_transport ( name ) : try : log . debug ( 'Using %s as transport' , name ) return TRANSPORT_LOOKUP [ name ] except KeyError : msg = 'Transport {} is not available. Are the dependencies installed?' . format ( name ) log . error ( msg , exc_info = True ) raise InvalidTransportException ( msg ) | Return the transport class . |
233,510 | def start ( self ) : zmq_uri = '{protocol}://{address}:{port}' . format ( protocol = self . protocol , address = self . address , port = self . port ) if self . port else '{protocol}://{address}' . format ( protocol = self . protocol , address = self . address ) log . debug ( 'ZMQ URI: %s' , zmq_uri ) self . ctx = zmq ... | Startup the zmq consumer . |
233,511 | def receive ( self ) : try : msg = self . sub . recv ( ) except zmq . Again as error : log . error ( 'Unable to receive messages: %s' , error , exc_info = True ) raise ListenerException ( error ) log . debug ( '[%s] Received %s' , time . time ( ) , msg ) return msg , '' | Return the message received . |
233,512 | def stop ( self ) : log . info ( 'Stopping the zmq listener class' ) self . sub . close ( ) self . ctx . term ( ) | Shutdown zmq listener . |
233,513 | def start ( self ) : if ':' in self . address : self . skt = socket . socket ( socket . AF_INET6 , socket . SOCK_DGRAM ) else : self . skt = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) if self . reuse_port : self . skt . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) if hasattr ( socket ,... | Create the UDP listener socket . |
233,514 | def _suicide_when_without_parent ( self , parent_pid ) : while True : time . sleep ( 5 ) try : os . kill ( parent_pid , 0 ) except OSError : self . stop ( ) log . warning ( 'The parent is not alive, exiting.' ) os . _exit ( 999 ) | Kill this process when the parent died . |
233,515 | def _setup_buffer ( self ) : if not self . _buffer_cfg or not isinstance ( self . _buffer_cfg , dict ) : return buffer_name = list ( self . _buffer_cfg . keys ( ) ) [ 0 ] buffer_class = napalm_logs . buffer . get_interface ( buffer_name ) log . debug ( 'Setting up buffer interface "%s"' , buffer_name ) if 'expire_time'... | Setup the buffer subsystem . |
233,516 | def _setup_metrics ( self ) : path = os . environ . get ( "prometheus_multiproc_dir" ) if not os . path . exists ( self . metrics_dir ) : try : log . info ( "Creating metrics directory" ) os . makedirs ( self . metrics_dir ) except OSError : log . error ( "Failed to create metrics directory!" ) raise ConfigurationExcep... | Start metric exposition |
233,517 | def _setup_log ( self ) : logging_level = CONFIG . LOGGING_LEVEL . get ( self . log_level . lower ( ) ) logging . basicConfig ( format = self . log_format , level = logging_level ) | Setup the log object . |
233,518 | def _whitelist_blacklist ( self , os_name ) : return napalm_logs . ext . check_whitelist_blacklist ( os_name , whitelist = self . device_whitelist , blacklist = self . device_blacklist ) | Determines if the OS should be ignored depending on the whitelist - blacklist logic configured by the user . |
233,519 | def _extract_yaml_docstring ( stream ) : comment_lines = [ ] lines = stream . read ( ) . splitlines ( ) for line in lines : line_strip = line . strip ( ) if not line_strip : continue if line_strip . startswith ( '#' ) : comment_lines . append ( line_strip . replace ( '#' , '' , 1 ) . strip ( ) ) else : break return ' '... | Extract the comments at the top of the YAML file from the stream handler . Return the extracted comment as string . |
233,520 | def _verify_config_dict ( self , valid , config , dev_os , key_path = None ) : if not key_path : key_path = [ ] for key , value in valid . items ( ) : self . _verify_config_key ( key , value , valid , config , dev_os , key_path ) | Verify if the config dict is valid . |
233,521 | def _verify_config ( self ) : if not self . config_dict : self . _raise_config_exception ( 'No config found' ) for dev_os , dev_config in self . config_dict . items ( ) : if not dev_config : log . warning ( 'No config found for %s' , dev_os ) continue self . _verify_config_dict ( CONFIG . VALID_CONFIG , dev_config , de... | Verify that the config is correct |
233,522 | def _build_config ( self ) : if not self . config_dict : if not self . config_path : self . config_path = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , 'config' ) log . info ( 'Reading the configuration from %s' , self . config_path ) self . config_dict = self . _load_config ( self . co... | Build the config of the napalm syslog parser . |
233,523 | def _start_auth_proc ( self ) : log . debug ( 'Computing the signing key hex' ) verify_key = self . __signing_key . verify_key sgn_verify_hex = verify_key . encode ( encoder = nacl . encoding . HexEncoder ) log . debug ( 'Starting the authenticator subprocess' ) auth = NapalmLogsAuthProc ( self . certificate , self . k... | Start the authenticator process . |
233,524 | def _start_lst_proc ( self , listener_type , listener_opts ) : log . debug ( 'Starting the listener process for %s' , listener_type ) listener = NapalmLogsListenerProc ( self . opts , self . address , self . port , listener_type , listener_opts = listener_opts ) proc = Process ( target = listener . start ) proc . start... | Start the listener process . |
233,525 | def _start_srv_proc ( self , started_os_proc ) : log . debug ( 'Starting the server process' ) server = NapalmLogsServerProc ( self . opts , self . config_dict , started_os_proc , buffer = self . _buffer ) proc = Process ( target = server . start ) proc . start ( ) proc . description = 'Server process' log . debug ( 'S... | Start the server process . |
233,526 | def _start_pub_proc ( self , publisher_type , publisher_opts , pub_id ) : log . debug ( 'Starting the publisher process for %s' , publisher_type ) publisher = NapalmLogsPublisherProc ( self . opts , self . publish_address , self . publish_port , publisher_type , self . serializer , self . __priv_key , self . __signing_... | Start the publisher process . |
233,527 | def _start_dev_proc ( self , device_os , device_config ) : log . info ( 'Starting the child process for %s' , device_os ) dos = NapalmLogsDeviceProc ( device_os , self . opts , device_config ) os_proc = Process ( target = dos . start ) os_proc . start ( ) os_proc . description = '%s device process' % device_os log . de... | Start the device worker process . |
233,528 | def _check_children ( self ) : while self . up : time . sleep ( 1 ) for process in self . _processes : if process . is_alive ( ) is True : continue log . debug ( '%s is dead. Stopping the napalm-logs engine.' , process . description ) self . stop_engine ( ) | Check all of the child processes are still running |
233,529 | def _setup_ipc ( self ) : log . debug ( 'Setting up the internal IPC proxy' ) self . ctx = zmq . Context ( ) self . sub = self . ctx . socket ( zmq . SUB ) self . sub . bind ( PUB_PX_IPC_URL ) self . sub . setsockopt ( zmq . SUBSCRIBE , b'' ) log . debug ( 'Setting HWM for the proxy frontend: %d' , self . hwm ) try : s... | Setup the IPC PUB and SUB sockets for the proxy . |
233,530 | def _setup_ipc ( self ) : self . ctx = zmq . Context ( ) log . debug ( 'Setting up the %s publisher subscriber #%d' , self . _transport_type , self . pub_id ) self . sub = self . ctx . socket ( zmq . SUB ) self . sub . connect ( PUB_IPC_URL ) self . sub . setsockopt ( zmq . SUBSCRIBE , b'' ) try : self . sub . setsocko... | Subscribe to the pub IPC and publish the messages on the right transport . |
233,531 | def _prepare ( self , serialized_obj ) : nonce = nacl . utils . random ( nacl . secret . SecretBox . NONCE_SIZE ) encrypted = self . __safe . encrypt ( serialized_obj , nonce ) signed = self . __signing_key . sign ( encrypted ) return signed | Prepare the object to be sent over the untrusted channel . |
233,532 | def get_listener ( name ) : try : log . debug ( 'Using %s as listener' , name ) return LISTENER_LOOKUP [ name ] except KeyError : msg = 'Listener {} is not available. Are the dependencies installed?' . format ( name ) log . error ( msg , exc_info = True ) raise InvalidListenerException ( msg ) | Return the listener class . |
233,533 | def _start_keep_alive ( self ) : keep_alive_thread = threading . Thread ( target = self . keep_alive ) keep_alive_thread . daemon = True keep_alive_thread . start ( ) | Start the keep alive thread as a daemon |
233,534 | def keep_alive ( self ) : self . ssl_skt . settimeout ( defaults . AUTH_KEEP_ALIVE_INTERVAL ) while self . __up : try : log . debug ( 'Sending keep-alive message to the server' ) self . ssl_skt . send ( defaults . AUTH_KEEP_ALIVE ) except socket . error : log . error ( 'Unable to send keep-alive message to the server.'... | Send a keep alive request periodically to make sure that the server is still alive . If not then try to reconnect . |
233,535 | def reconnect ( self ) : log . debug ( 'Closing the SSH socket.' ) try : self . ssl_skt . close ( ) except socket . error : log . error ( 'The socket seems to be closed already.' ) log . debug ( 'Re-opening the SSL socket.' ) self . authenticate ( ) | Try to reconnect and re - authenticate with the server . |
233,536 | def authenticate ( self ) : log . debug ( 'Authenticate to %s:%d, using the certificate %s' , self . address , self . port , self . certificate ) if ':' in self . address : skt_ver = socket . AF_INET6 else : skt_ver = socket . AF_INET skt = socket . socket ( skt_ver , socket . SOCK_STREAM ) self . ssl_skt = ssl . wrap_... | Authenticate the client and return the private and signature keys . |
233,537 | def decrypt ( self , binary ) : try : encrypted = self . verify_key . verify ( binary ) except BadSignatureError : log . error ( 'Signature was forged or corrupt' , exc_info = True ) raise BadSignatureException ( 'Signature was forged or corrupt' ) try : packed = self . priv_key . decrypt ( encrypted ) except CryptoErr... | Decrypt and unpack the original OpenConfig object serialized using MessagePack . Raise BadSignatureException when the signature was forged or corrupted . |
233,538 | def _client_connection ( self , conn , addr ) : log . debug ( 'Established connection with %s:%d' , addr [ 0 ] , addr [ 1 ] ) conn . settimeout ( self . socket_timeout ) try : while self . __up : msg = conn . recv ( self . buffer_size ) if not msg : continue log . debug ( '[%s] Received %s from %s. Adding in the queue'... | Handle the connecition with one client . |
233,539 | def _serve_clients ( self ) : self . __up = True while self . __up : log . debug ( 'Waiting for a client to connect' ) try : conn , addr = self . skt . accept ( ) log . debug ( 'Received connection from %s:%d' , addr [ 0 ] , addr [ 1 ] ) except socket . error as error : if not self . __up : return msg = 'Received liste... | Accept cients and serve one separate thread per client . |
233,540 | def start ( self ) : log . debug ( 'Creating the TCP server' ) if ':' in self . address : self . skt = socket . socket ( socket . AF_INET6 , socket . SOCK_STREAM ) else : self . skt = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) if self . reuse_port : self . skt . setsockopt ( socket . SOL_SOCKET , socke... | Start listening for messages . |
233,541 | def receive ( self ) : while self . buffer . empty ( ) and self . __up : sleep_ms = random . randint ( 0 , 1000 ) time . sleep ( sleep_ms / 1000.0 ) if not self . buffer . empty ( ) : return self . buffer . get ( block = False ) return '' , '' | Return one message dequeued from the listen buffer . |
233,542 | def stop ( self ) : log . info ( 'Stopping the TCP listener' ) self . __up = False try : self . skt . shutdown ( socket . SHUT_RDWR ) except socket . error : log . error ( 'The following error may not be critical:' , exc_info = True ) self . skt . close ( ) | Closing the socket . |
233,543 | def _setup_ipc ( self ) : log . debug ( 'Setting up the listener IPC pusher' ) self . ctx = zmq . Context ( ) self . pub = self . ctx . socket ( zmq . PUSH ) self . pub . connect ( LST_IPC_URL ) log . debug ( 'Setting HWM for the listener: %d' , self . opts [ 'hwm' ] ) try : self . pub . setsockopt ( zmq . HWM , self .... | Setup the listener ICP pusher . |
233,544 | def make_update_loop ( thread , update_func ) : while not thread . should_stop ( ) : if thread . should_pause ( ) : thread . wait_to_resume ( ) start = time . time ( ) if hasattr ( thread , '_updated' ) : thread . _updated . clear ( ) update_func ( ) if hasattr ( thread , '_updated' ) : thread . _updated . set ( ) end ... | Makes a run loop which calls an update function at a predefined frequency . |
233,545 | def start ( self ) : if self . running : self . stop ( ) self . _thread = threading . Thread ( target = self . _wrapped_target ) self . _thread . daemon = True self . _thread . start ( ) | Start the run method as a new thread . |
233,546 | def wait_to_start ( self , allow_failure = False ) : self . _started . wait ( ) if self . _crashed and not allow_failure : self . _thread . join ( ) raise RuntimeError ( 'Setup failed, see {} Traceback' 'for details.' . format ( self . _thread . name ) ) | Wait for the thread to actually starts . |
233,547 | def from_vrep ( config , vrep_host = '127.0.0.1' , vrep_port = 19997 , scene = None , tracked_objects = [ ] , tracked_collisions = [ ] , id = None , shared_vrep_io = None ) : if shared_vrep_io is None : vrep_io = VrepIO ( vrep_host , vrep_port ) else : vrep_io = shared_vrep_io vreptime = vrep_time ( vrep_io ) pypot_tim... | Create a robot from a V - REP instance . |
233,548 | def set_wheel_mode ( self , ids ) : self . set_control_mode ( dict ( zip ( ids , itertools . repeat ( 'wheel' ) ) ) ) | Sets the specified motors to wheel mode . |
233,549 | def set_joint_mode ( self , ids ) : self . set_control_mode ( dict ( zip ( ids , itertools . repeat ( 'joint' ) ) ) ) | Sets the specified motors to joint mode . |
233,550 | def set_angle_limit ( self , limit_for_id , ** kwargs ) : convert = kwargs [ 'convert' ] if 'convert' in kwargs else self . _convert if 'wheel' in self . get_control_mode ( limit_for_id . keys ( ) ) : raise ValueError ( 'can not change the angle limit of a motor in wheel mode' ) if ( 0 , 0 ) in limit_for_id . values ( ... | Sets the angle limit to the specified motors . |
233,551 | def close ( self ) : self . stop_sync ( ) [ c . io . close ( ) for c in self . _controllers if c . io is not None ] | Cleans the robot by stopping synchronization and all controllers . |
233,552 | def goto_position ( self , position_for_motors , duration , control = None , wait = False ) : for i , ( motor_name , position ) in enumerate ( position_for_motors . iteritems ( ) ) : w = False if i < len ( position_for_motors ) - 1 else wait m = getattr ( self , motor_name ) m . goto_position ( position , duration , co... | Moves a subset of the motors to a position within a specific duration . |
233,553 | def power_up ( self ) : for m in self . motors : m . compliant = False m . moving_speed = 0 m . torque_limit = 100.0 | Changes all settings to guarantee the motors will be used at their maximum power . |
233,554 | def to_config ( self ) : from . . dynamixel . controller import DxlController dxl_controllers = [ c for c in self . _controllers if isinstance ( c , DxlController ) ] config = { } config [ 'controllers' ] = { } for i , c in enumerate ( dxl_controllers ) : name = 'dxl_controller_{}' . format ( i ) config [ 'controllers'... | Generates the config for the current robot . |
233,555 | def update ( self ) : h , _ , l , _ = self . io . call_remote_api ( 'simxGetObjectGroupData' , remote_api . sim_object_joint_type , 16 , streaming = True ) limits4handle = { hh : ( ll , lr ) for hh , ll , lr in zip ( h , l [ : : 2 ] , l [ 1 : : 2 ] ) } for m in self . motors : tmax = torque_max [ m . model ] p = round ... | Synchronization update loop . |
233,556 | def update ( self ) : for s in self . sensors : s . position = self . io . get_object_position ( object_name = s . name ) s . orientation = self . io . get_object_orientation ( object_name = s . name ) | Updates the position and orientation of the tracked objects . |
233,557 | def update ( self ) : for s in self . sensors : s . colliding = self . io . get_collision_state ( collision_name = s . name ) | Update the state of the collision detectors . |
233,558 | def get_transformation_matrix ( self , theta ) : ct = numpy . cos ( theta + self . theta ) st = numpy . sin ( theta + self . theta ) ca = numpy . cos ( self . alpha ) sa = numpy . sin ( self . alpha ) return numpy . matrix ( ( ( ct , - st * ca , st * sa , self . a * ct ) , ( st , ct * ca , - ct * sa , self . a * st ) ,... | Computes the homogeneous transformation matrix for this link . |
233,559 | def forward_kinematics ( self , q ) : q = numpy . array ( q ) . flatten ( ) if len ( q ) != len ( self . links ) : raise ValueError ( 'q must contain as element as the number of links' ) tr = self . base . copy ( ) l = [ ] for link , theta in zip ( self . links , q ) : tr = tr * link . get_transformation_matrix ( theta... | Computes the homogeneous transformation matrix of the end effector of the chain . |
233,560 | def inverse_kinematics ( self , end_effector_transformation , q = None , max_iter = 1000 , tolerance = 0.05 , mask = numpy . ones ( 6 ) , use_pinv = False ) : if q is None : q = numpy . zeros ( ( len ( self . links ) , 1 ) ) q = numpy . matrix ( q . reshape ( - 1 , 1 ) ) best_e = numpy . ones ( 6 ) * numpy . inf best_q... | Computes the joint angles corresponding to the end effector transformation . |
233,561 | def _get_available_ports ( ) : if platform . system ( ) == 'Darwin' : return glob . glob ( '/dev/tty.usb*' ) elif platform . system ( ) == 'Linux' : return glob . glob ( '/dev/ttyACM*' ) + glob . glob ( '/dev/ttyUSB*' ) + glob . glob ( '/dev/ttyAMA*' ) elif sys . platform . lower ( ) == 'cygwin' : return glob . glob ( ... | Tries to find the available serial ports on your system . |
233,562 | def find_port ( ids , strict = True ) : ids_founds = [ ] for port in get_available_ports ( ) : for DxlIOCls in ( DxlIO , Dxl320IO ) : try : with DxlIOCls ( port ) as dxl : _ids_founds = dxl . scan ( ids ) ids_founds += _ids_founds if strict and len ( _ids_founds ) == len ( ids ) : return port if not strict and len ( _i... | Find the port with the specified attached motor ids . |
233,563 | def _filter ( self , data ) : filtered_data = [ ] for queue , data in zip ( self . _raw_data_queues , data ) : queue . append ( data ) filtered_data . append ( numpy . median ( queue ) ) return filtered_data | Apply a filter to reduce noisy data . |
233,564 | def setup ( self ) : [ c . start ( ) for c in self . controllers ] [ c . wait_to_start ( ) for c in self . controllers ] | Starts all the synchronization loops . |
233,565 | def from_poppy_creature ( cls , poppy , motors , passiv , tip , reversed_motors = [ ] ) : chain_elements = get_chain_from_joints ( poppy . urdf_file , [ m . name for m in motors ] ) activ = [ False ] + [ m not in passiv for m in motors ] + [ True ] chain = cls . from_urdf_file ( poppy . urdf_file , base_elements = chai... | Creates an kinematic chain from motors of a Poppy Creature . |
233,566 | def goto ( self , position , duration , wait = False , accurate = False ) : if len ( position ) != 3 : raise ValueError ( 'Position should be a list [x, y, z]!' ) M = eye ( 4 ) M [ : 3 , 3 ] = position self . _goto ( M , duration , wait , accurate ) | Goes to a given cartesian position . |
233,567 | def _goto ( self , pose , duration , wait , accurate ) : kwargs = { } if not accurate : kwargs [ 'max_iter' ] = 3 q0 = self . convert_to_ik_angles ( self . joints_position ) q = self . inverse_kinematics ( pose , initial_position = q0 , ** kwargs ) joints = self . convert_from_ik_angles ( q ) last = self . motors [ - 1... | Goes to a given cartesian pose . |
233,568 | def convert_to_ik_angles ( self , joints ) : if len ( joints ) != len ( self . motors ) : raise ValueError ( 'Incompatible data, len(joints) should be {}!' . format ( len ( self . motors ) ) ) raw_joints = [ ( j + m . offset ) * ( 1 if m . direct else - 1 ) for j , m in zip ( joints , self . motors ) ] raw_joints *= se... | Convert from poppy representation to IKPY internal representation . |
233,569 | def convert_from_ik_angles ( self , joints ) : if len ( joints ) != len ( self . motors ) + 2 : raise ValueError ( 'Incompatible data, len(joints) should be {}!' . format ( len ( self . motors ) + 2 ) ) joints = [ rad2deg ( j ) for j in joints [ 1 : - 1 ] ] joints *= self . _reversed return [ ( j * ( 1 if m . direct el... | Convert from IKPY internal representation to poppy representation . |
233,570 | def factory_reset ( self , ids , except_ids = False , except_baudrate_and_ids = False ) : mode = ( 0x02 if except_baudrate_and_ids else 0x01 if except_ids else 0xFF ) for id in ids : try : self . _send_packet ( self . _protocol . DxlResetPacket ( id , mode ) ) except ( DxlTimeoutError , DxlCommunicationError ) : pass | Reset all motors on the bus to their factory default settings . |
233,571 | def stop ( self , wait = True ) : logger . info ( "Primitive %s stopped." , self ) StoppableThread . stop ( self , wait ) | Requests the primitive to stop . |
233,572 | def recent_update_frequencies ( self ) : return list ( reversed ( [ ( 1.0 / p ) for p in numpy . diff ( self . _recent_updates ) ] ) ) | Returns the 10 most recent update frequencies . |
233,573 | def goto_position ( self , position , duration , control = None , wait = False ) : if control is None : control = self . goto_behavior if control == 'minjerk' : goto_min_jerk = GotoMinJerk ( self , position , duration ) goto_min_jerk . start ( ) if wait : goto_min_jerk . wait_to_stop ( ) elif control == 'dummy' : dp = ... | Automatically sets the goal position and the moving speed to reach the desired position within the duration . |
233,574 | def add_tracked_motors ( self , tracked_motors ) : new_mockup_motors = map ( self . get_mockup_motor , tracked_motors ) self . tracked_motors = list ( set ( self . tracked_motors + new_mockup_motors ) ) | Add new motors to the recording |
233,575 | def update ( self ) : with self . syncing : for m in self . _motors : to_set = defaultdict ( list ) for p in self . _prim : for key , val in getattr ( p . robot , m . name ) . _to_set . iteritems ( ) : to_set [ key ] . append ( val ) for key , val in to_set . iteritems ( ) : if key == 'led' : colors = set ( val ) if le... | Combined at a predefined frequency the request orders and affect them to the real motors . |
233,576 | def stop ( self ) : for p in self . primitives [ : ] : p . stop ( ) StoppableLoopThread . stop ( self ) | Stop the primitive manager . |
233,577 | def load_scene ( self , scene_path , start = False ) : self . stop_simulation ( ) if not os . path . exists ( scene_path ) : raise IOError ( "No such file or directory: '{}'" . format ( scene_path ) ) self . call_remote_api ( 'simxLoadScene' , scene_path , True ) if start : self . start_simulation ( ) | Loads a scene on the V - REP server . |
233,578 | def get_motor_position ( self , motor_name ) : return self . call_remote_api ( 'simxGetJointPosition' , self . get_object_handle ( motor_name ) , streaming = True ) | Gets the motor current position . |
233,579 | def set_motor_position ( self , motor_name , position ) : self . call_remote_api ( 'simxSetJointTargetPosition' , self . get_object_handle ( motor_name ) , position , sending = True ) | Sets the motor target position . |
233,580 | def set_motor_force ( self , motor_name , force ) : self . call_remote_api ( 'simxSetJointForce' , self . get_object_handle ( motor_name ) , force , sending = True ) | Sets the maximum force or torque that a joint can exert . |
233,581 | def get_object_position ( self , object_name , relative_to_object = None ) : h = self . get_object_handle ( object_name ) relative_handle = ( - 1 if relative_to_object is None else self . get_object_handle ( relative_to_object ) ) return self . call_remote_api ( 'simxGetObjectPosition' , h , relative_handle , streaming... | Gets the object position . |
233,582 | def set_object_position ( self , object_name , position = [ 0 , 0 , 0 ] ) : h = self . get_object_handle ( object_name ) return self . call_remote_api ( 'simxSetObjectPosition' , h , - 1 , position , sending = True ) | Sets the object position . |
233,583 | def get_object_handle ( self , obj ) : if obj not in self . _object_handles : self . _object_handles [ obj ] = self . _get_object_handle ( obj = obj ) return self . _object_handles [ obj ] | Gets the vrep object handle . |
233,584 | def get_collision_state ( self , collision_name ) : return self . call_remote_api ( 'simxReadCollision' , self . get_collision_handle ( collision_name ) , streaming = True ) | Gets the collision state . |
233,585 | def get_collision_handle ( self , collision ) : if collision not in self . _object_handles : h = self . _get_collision_handle ( collision ) self . _object_handles [ collision ] = h return self . _object_handles [ collision ] | Gets a vrep collisions handle . |
233,586 | def change_object_name ( self , old_name , new_name ) : h = self . _get_object_handle ( old_name ) if old_name in self . _object_handles : self . _object_handles . pop ( old_name ) lua_code = "simSetObjectName({}, '{}')" . format ( h , new_name ) self . _inject_lua_code ( lua_code ) | Change object name |
233,587 | def _create_pure_shape ( self , primitive_type , options , sizes , mass , precision ) : lua_code = "simCreatePureShape({}, {}, {{{}, {}, {}}}, {}, {{{}, {}}})" . format ( primitive_type , options , sizes [ 0 ] , sizes [ 1 ] , sizes [ 2 ] , mass , precision [ 0 ] , precision [ 1 ] ) self . _inject_lua_code ( lua_code ) | Create Pure Shape |
233,588 | def _inject_lua_code ( self , lua_code ) : msg = ( ctypes . c_ubyte * len ( lua_code ) ) . from_buffer_copy ( lua_code . encode ( ) ) self . call_remote_api ( 'simxWriteStringStream' , 'my_lua_code' , msg ) | Sends raw lua code and evaluate it wihtout any checking! |
233,589 | def call_remote_api ( self , func_name , * args , ** kwargs ) : f = getattr ( remote_api , func_name ) mode = self . _extract_mode ( kwargs ) kwargs [ 'operationMode' ] = vrep_mode [ mode ] if '_force' in kwargs : del kwargs [ '_force' ] _force = True else : _force = False for _ in range ( VrepIO . MAX_ITER ) : with se... | Calls any remote API func in a thread_safe way . |
233,590 | def run ( self , ** kwargs ) : try : loop = IOLoop ( ) app = self . make_app ( ) app . listen ( self . port ) loop . start ( ) except socket . error as serr : if serr . errno != errno . EADDRINUSE : raise serr else : logger . warning ( 'The webserver port {} is already used. May be the HttpRobotServer is already runnin... | Start the tornado server run forever |
233,591 | def close ( self , _force_lock = False ) : if not self . closed : with self . __force_lock ( _force_lock ) or self . _serial_lock : self . _serial . close ( ) self . __used_ports . remove ( self . port ) logger . info ( "Closing port '%s'" , self . port , extra = { 'port' : self . port , 'baudrate' : self . baudrate , ... | Closes the serial communication if opened . |
233,592 | def ping ( self , id ) : pp = self . _protocol . DxlPingPacket ( id ) try : self . _send_packet ( pp , error_handler = None ) return True except DxlTimeoutError : return False | Pings the motor with the specified id . |
233,593 | def scan ( self , ids = range ( 254 ) ) : return [ id for id in ids if self . ping ( id ) ] | Pings all ids within the specified list by default it finds all the motors connected to the bus . |
233,594 | def get_model ( self , ids ) : to_get_ids = [ i for i in ids if i not in self . _known_models ] models = [ dxl_to_model ( m ) for m in self . _get_model ( to_get_ids , convert = False ) ] self . _known_models . update ( zip ( to_get_ids , models ) ) return tuple ( self . _known_models [ id ] for id in ids ) | Gets the model for the specified motors . |
233,595 | def change_baudrate ( self , baudrate_for_ids ) : self . _change_baudrate ( baudrate_for_ids ) for motor_id in baudrate_for_ids : if motor_id in self . _known_models : del self . _known_models [ motor_id ] if motor_id in self . _known_mode : del self . _known_mode [ motor_id ] | Changes the baudrate of the specified motors . |
233,596 | def get_status_return_level ( self , ids , ** kwargs ) : convert = kwargs [ 'convert' ] if 'convert' in kwargs else self . _convert srl = [ ] for id in ids : try : srl . extend ( self . _get_status_return_level ( ( id , ) , error_handler = None , convert = convert ) ) except DxlTimeoutError as e : if self . ping ( id )... | Gets the status level for the specified motors . |
233,597 | def set_status_return_level ( self , srl_for_id , ** kwargs ) : convert = kwargs [ 'convert' ] if 'convert' in kwargs else self . _convert if convert : srl_for_id = dict ( zip ( srl_for_id . keys ( ) , [ ( 'never' , 'read' , 'always' ) . index ( s ) for s in srl_for_id . values ( ) ] ) ) self . _set_status_return_level... | Sets status return level to the specified motors . |
233,598 | def switch_led_on ( self , ids ) : self . _set_LED ( dict ( zip ( ids , itertools . repeat ( True ) ) ) ) | Switches on the LED of the motors with the specified ids . |
233,599 | def switch_led_off ( self , ids ) : self . _set_LED ( dict ( zip ( ids , itertools . repeat ( False ) ) ) ) | Switches off the LED of the motors with the specified ids . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.