ckbot :: posable :: PoseRecorder :: Class PoseRecorder
[hide private]
[frames] | no frames]

Class PoseRecorder

source code


Concrete class PoseRecorder

Provides a convenient interface for 'poseable programming' by allowing positions of servos to be recorded and played back.

Convenience methods for saving and loading .csv files are also provided

For typical usage, see the source code for recordFromCluster()

Instance Methods [hide private]
 
__init__(self, mods)
Initialize the PoseRecorder to record a list of modules
source code
 
getPose(self)
collect positions of all servos
source code
 
_set_pose(self, pose)
(private) set positions of all servos
source code
 
off(self)
Emegency Stop for all servos -- .go_slack()-s all modules, ignoring any exceptions
source code
 
reset(self)
Reset the recording, allowing a new recording to be started
source code
 
snap(self, t=None)
Add a snapshot of the current pose to the recording
source code
 
snapClosed(self, dt=1)
Add the first pose at the end of the recording, with specified delay.
source code
 
show(self, stream=STDOUT, delim=" ", fmt="%5d", hfmt="%5s", rdel="\n", slc=slice(None))
Write the current recording out on a stream in a text-based format
source code
 
unsnap(self)
Drop the last pose from the recording
source code
 
appendFrom(self, stream, cdel=",", dt=1)
append a recording from a textual representation
source code
 
loadCSV(self, stream)
Syntactic sugar for loading a .csv file using .appendFrom()
source code
 
saveCSV(self, stream=STDOUT)
Syntactic sugar for using .show() to write a .csv formatted recording
source code
 
playback(self, period=None, count=1, rate=0.03)
Play back the current recording one or more times.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, mods)
(Constructor)

source code 
Initialize the PoseRecorder to record a list of modules

INPUT:
  mods -- sequence of modules with .get_pos(), .set_pos() and .go_slack() methods

Overrides: object.__init__

snapClosed(self, dt=1)

source code 
Add the first pose at the end of the recording, with specified delay.
This allows loops to be cleanly repeated.

INPUT:
  dt -- float -- delay in seconds between last and first pose

show(self, stream=STDOUT, delim=" ", fmt="%5d", hfmt="%5s", rdel="\n", slc=slice(None))

source code 
Write the current recording out on a stream in a text-based format

INPUT:
  stream -- output stream object. Must support .write()
  delim -- str -- delimiter user between columns
  fmt -- str -- format string for numbers (except time)
  hfmt -- str -- format string for column headings
  rdel -- str -- row delimiter
  slc -- slice -- range of pose sequence to show

appendFrom(self, stream, cdel=",", dt=1)

source code 
append a recording from a textual representation
        
        INPUT:
          stream -- list -- a recording with one line per list entry
                 -- file -- a file containing a recording
          cdel -- str -- column delimiter
          dt -- float -- gap in time between last entry and newly loaded data
        
        Caveats: 
          (1) columns must match the list of servos for which the 
              PoseRecorder was configured.
          (2) the first (header) row of the file is ignored
    
        Example: load froma literal multiline string
        >>> pr.appendFrom('''
        0, 1000, 0, 1000
        1,    0, 1000, 0
        '''.split("
"))
        

saveCSV(self, stream=STDOUT)

source code 
Syntactic sugar for using .show() to write a .csv formatted recording

INPUT:
  stream -- a file object or a file path. The '.csv' will be added if missing

Typical usage:
  pr.saveCSV('motion.csv')

playback(self, period=None, count=1, rate=0.03)

source code 
Play back the current recording one or more times.

INPUT:
  period -- float / None -- duration for entire recording
    if period is None, the recording timestamps are used
  count -- integer -- number of times to play
  rate -- float -- delay between commands sent (sec)