def load_choreography_sequence_from_txt_file(file_path): if not os.path.exists(file_path): LOGGER.error("File not found at: %s" % file_path) raise IOError("File not found at: %s" % file_path) choreography_sequence = choreography_sequence_pb2.ChoreographySequence() with open(file_path, "r") as f: data = f.read() text_format.Merge(data, choreography_sequence) return choreography_sequence
def load_choreography_sequence_from_binary_file(file_path): """Read a choreography sequence file into a protobuf ChoreographySequence message.""" if not os.path.exists(file_path): LOGGER.error("File not found at: %s" % file_path) raise IOError("File not found at: %s" % file_path) choreography_sequence = choreography_sequence_pb2.ChoreographySequence() with open(file_path, "rb") as f: data = f.read() choreography_sequence.ParseFromString(data) return choreography_sequence
def proto_to_choreo(self, cha_filename): """Function for uploading the animation file as a protobuf to the robot and then turning the animation into a choreography sequence which can then be played on the robot. Args: cha_filename (string): Name of the *.cha animation file to be uploaded to the robot. Returns: The animation protobuf name. The choreography sequence containing the animation move described by the *.cha animation file. """ # path to the *.cha animation file to be uploaded fpath = os.path.join(self._download_filepath, self._animation_directory) animated_file = os.path.join(fpath, cha_filename) # use the *.cha animation file to create an animation protobuf file. convert_animation_file_to_proto can take a second # optional argument for a filepath to a file containing the default values for animation parameter fields, but Animation # Recorder doesn't produce any animations that have parameter fields so only the *.cha animation file is needed. animation = convert_animation_file_to_proto(animated_file) #upload the created animation protobuf to the robot self._upload_animation_proto(animation) # turn animation into a choreography sequence: # initialize a ChoreographySequence object choreography_seq = choreography_sequence_pb2.ChoreographySequence() # assign the ChoreographySequence name to be the animation protobuf name choreography_seq.name = animation.name # assign the playback speed of the choreography sequence choreography_seq.slices_per_minute = 200 * 4 # the MoveParamsList will contain the list of moves making up the choreography sequence. For Animation Recorder # the choreography sequences are one move long, where the move is the motion captured by the recording. MoveParamsList = [] move_param = choreography_sequence_pb2.MoveParams() move_param.type = "animation" # start the move immediately with no delay move_param.start_slice = 0 # calculate the expected duration of the move in slices by multiplying the duration of the animation in minutes by the # number of slices per minute of the created choreography sequence. move_param.requested_slices = math.ceil(((animation.proto.animation_keyframes[-1].time - animation.proto.animation_keyframes[0].time)/ 60) * choreography_seq.slices_per_minute) # assign the move the name of the animation protobuf move_param.animate_params.animation_name = animation.name # add the move to the list of moves MoveParamsList.append(move_param) # add the list of moves to the choreography sequence choreography_seq.moves.extend(MoveParamsList) # upload the choreography sequence to the robot upload_response = self._choreo_client.upload_choreography(choreography_seq, non_strict_parsing=True) # return the animation protobuf and choreography sequence return animation, choreography_seq