Goulib.motion module

motion simulation (kinematics)

class Goulib.motion.PVA(funcs)[source]

Bases: Goulib.plot.Plot

represents a function of time returning position, velocity, and acceleration

__init__(funcs)[source]
__call__(t, t0=0)[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

html(**kwargs)
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
render(fmt='svg', **kwargs)
save(filename, **kwargs)
svg(**kwargs)
class Goulib.motion.Segment(t0, t1, funcs)[source]

Bases: Goulib.motion.PVA

a PVA defined between 2 times, null elsewhere

__init__(t0, t1, funcs)[source]
dt()[source]
start()[source]
startPos()[source]
startSpeed()[source]
startAcc()[source]
startJerk()[source]
startTime()[source]
end()[source]
endPos()[source]
endSpeed()[source]
endAcc()[source]
endJerk()[source]
endTime()[source]
timeWhenPosBiggerThan(pos, resolution=0.01)[source]

search the first time when the position is bigger than pos :params pos: the pos that must at least be reached :params resolution: the time resolution in sec

__call__(t)[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

html(**kwargs)
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
render(fmt='svg', **kwargs)
save(filename, **kwargs)
svg(**kwargs)
class Goulib.motion.Segments(segments=[], label='Segments')[source]

Bases: Goulib.motion.Segment

can be initialized with a list of segment (that of course can also be a Segments) :param label: a label can be given

__init__(segments=[], label='Segments')[source]

can be initialized with a list of segment (that of course can also be a Segments) :param label: a label can be given

__str__()[source]
html()[source]
update()[source]

yet only calculates t0 and t1

insert(segment, autoJoin=True)[source]

insert a segment into Segments :param segment: the segment to add. must be in a range that is not already defined or it will rise a value error exception :param autoJoin: if True and the added segment has the same starting position as the last segment’s end

and both velocity are 0 then a segment of (pos,v=0,a=0) is automatically added. this help discribing movements only where there is curently a movement
add(segments, autoJoin=True)[source]

add a segment or a list of segment to the segments

start()[source]
end()[source]
__call__(t)[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

dt()
endAcc()
endJerk()
endPos()
endSpeed()
endTime()
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
render(fmt='svg', **kwargs)
save(filename, **kwargs)
startAcc()
startJerk()
startPos()
startSpeed()
startTime()
svg(**kwargs)
timeWhenPosBiggerThan(pos, resolution=0.01)

search the first time when the position is bigger than pos :params pos: the pos that must at least be reached :params resolution: the time resolution in sec

class Goulib.motion.SegmentPoly(t0, t1, p)[source]

Bases: Goulib.motion.Segment

a segment defined by a polynomial position law

__init__(t0, t1, p)[source]
__call__(t)
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

dt()
end()
endAcc()
endJerk()
endPos()
endSpeed()
endTime()
html(**kwargs)
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
render(fmt='svg', **kwargs)
save(filename, **kwargs)
start()
startAcc()
startJerk()
startPos()
startSpeed()
startTime()
svg(**kwargs)
timeWhenPosBiggerThan(pos, resolution=0.01)

search the first time when the position is bigger than pos :params pos: the pos that must at least be reached :params resolution: the time resolution in sec

class Goulib.motion.Actuator(stateMachine, vmax, acc, name='', pos=<Quantity(0, 'meter')>, distPerTurn=<Quantity(1, 'millimeter')>, angle=<Quantity(0, 'degree')>, mass=<Quantity(1, 'kilogram')>, friction=<Quantity(0, 'newton')>)[source]

Bases: object

simulate an actuator. each movements are recorded in a Segments object the goal of this class is to simplify the writing in most common cases

Params stateMachine:
 a stateMachine. the only requirement for the simulation is to have a .time as V(time,’s’) and a .displayMove boolean
Params acc:the default acceleration of the actuator
Params vmax:the default vmax
Params name:name of the actuator
Params pos:the initial position
Params distPerTurn:
 the distance of the actuator per motor (or reductor) turn
Params angle:if 0, the mass is moving horizontally, if 90° vertically: CAREFULL in that case the bigger the position, the higher
Params mass:the mass to move (for both intertia and lifting force)
Params friction:
 the friction force TODO: currently no difference between u0 and udynamique

intertia of the pulley should be taken into consideration

WARNING: the maxForce simulation is minimalist: as we know nothing about the reversibility of the grears and where is the friction, friction is always added even if it might be compensated by the mass in the case we go down

__init__(stateMachine, vmax, acc, name='', pos=<Quantity(0, 'meter')>, distPerTurn=<Quantity(1, 'millimeter')>, angle=<Quantity(0, 'degree')>, mass=<Quantity(1, 'kilogram')>, friction=<Quantity(0, 'newton')>)[source]
Params stateMachine:
 a stateMachine. the only requirement for the simulation is to have a .time as V(time,’s’) and a .displayMove boolean
Params acc:the default acceleration of the actuator
Params vmax:the default vmax
Params name:name of the actuator
Params pos:the initial position
Params distPerTurn:
 the distance of the actuator per motor (or reductor) turn
Params angle:if 0, the mass is moving horizontally, if 90° vertically: CAREFULL in that case the bigger the position, the higher
Params mass:the mass to move (for both intertia and lifting force)
Params friction:
 the friction force TODO: currently no difference between u0 and udynamique

intertia of the pulley should be taken into consideration

WARNING: the maxForce simulation is minimalist: as we know nothing about the reversibility of the grears and where is the friction, friction is always added even if it might be compensated by the mass in the case we go down

move(newpos, relative=False, time=None, wait=True, vmax=None, acc=None)[source]

moves the actuator to newpos :params newpos: the new absolute position :params time: the starting time of the move. by default (None) the state machine time will be used but

one can force the starting poing in the past typically to do parallel moves of different actuators
Params vmax:by default the values given at initialisation, but a value for this move can be given
Params acc:by default the values given at initialisation, but a value for this move can be given
endTime()[source]
P(t)[source]
maxAbsAcc()[source]
maxAbsSpeed()[source]
maxForce()[source]
maxTork()[source]
maxRpm()[source]
displayLast()[source]
display(fromTime=None, toTime=None)[source]
varNames()[source]

returns a list of internal variables. intended to be used in the Table.__init__

varRowUnits()[source]
varDict()[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

class Goulib.motion.TimeDiagram(actuators, stateMachines=[], fromTime=None, toTime=None)[source]

Bases: Goulib.plot.Plot

Params stateMachines:
 [(stateMachine,pos,posShift),…]
__init__(actuators, stateMachines=[], fromTime=None, toTime=None)[source]
Params stateMachines:
 [(stateMachine,pos,posShift),…]
__repr__()[source]
saveAsCsv(filename)[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

html(**kwargs)
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
render(fmt='svg', **kwargs)
save(filename, **kwargs)
svg(**kwargs)
Goulib.motion.ramp(dp, v0, v1, a)[source]
Parameters:
  • dp – float delta position or None if unknown
  • v0 – float initial velocity or None if unknown
  • v1 – float final velocity or None if unknown
  • a – float acceleration
Returns:

float shortest time to accelerate between constraints

Goulib.motion.trapeze(dp, vmax, a, v0=0, v2=0)[source]
Parameters:
  • dp – float delta position
  • vmax – float maximal velocity
  • a – float acceleration
  • v0 – float initial velocity, 0 by default
  • v2 – float final velocity, 0 by default
Returns:

tuple of 6 values:

  • time at end of acceleration
  • position at end of acceleration
  • velocity at end of acceleration
  • time at begin of deceleration
  • position at begin of deceleration
  • total time
Goulib.motion.Segment2ndDegree(t0, t1, start, end=None)[source]

calculates a constant acceleration Segment between start and end

Parameters:
  • t0,t1 – float start,end time. one of both may be None for undefined
  • start – (position, velocity, acceleration) float tuple. some values may be None for undefined
  • end – (position, velocity, acceleration) float tuple. some values may be None for undefined
Returns:

SegmentPoly

the function can cope with almost any combination of defined/undefined parameters, among others (see tests):

  • Segment2ndDegree(t0,t1,(p0,v0),p1) # time interval and start + end positions + initial speed
  • Segment2ndDegree(t0,t1,(p0,v0,a)) # time interval and start with acceleration
  • Segment2ndDegree(t0,t1,None,(p1,v1,a)) # time interval and end pva
  • Segment2ndDegree(t0,None,(p0,v0),(p1,v1)) # start + end positions + velocities
  • Segment2ndDegree(t0,None,(p0,v0,a),(None,v1)) # start pva + end velocity
  • Segment2ndDegree(None,t1,p0,(p1,v1,a)) # end pva + start position

the function also accepts some combinations of overconstraining parameters:

  • Segment2ndDegree(t0,t1,(p0,v0,a),p1) # time interval, start pva, end position => adjust t1
  • Segment2ndDegree(t0,t1,(p0,v0,a),(None,v1)) # time interval, start pva, v1=max vel => adjust t1
Raises:ValueError – when not enough parameters are specified to define the Segment univoquely
Goulib.motion.Segment4thDegree(t0, t1, start, end)[source]

smooth trajectory from an initial position and initial speed (p0,v0) to a final position and speed (p1,v1) * if t1<=t0, t1 is calculated

Goulib.motion.SegmentsTrapezoidalSpeed(t0, p0, p3, a, T=0, vmax=inf, v0=0, v3=0)[source]
Parameters:
  • t0 – float start time
  • p0 – float start position
  • p3 – float end position
  • a – float specified acceleration. if =0, use specified time
  • T – float specified time. if =0 (default), use specified acceleration
  • vmax – float max speed. default is infinity (i.e. triangular speed)
  • v0 – initial speed
  • v3

    final speed if T <> 0 then v3 = v0 v1 +——-+

    / / + v3
v0 +
| | |

t0 t1 t2 t3