Forces API
skelarm.forces
Replay a recorded tip force.
A run recorded with an external tip force, such as an arm pushed by hand in an
interactive simulator or by a force that :func:~skelarm.control.simulate_controlled
scripted, carries the force in its ext_force channel. :class:RecordedForce
replays that history by time, as an external_force for
:func:~skelarm.control.simulate_controlled: the same force at the same times,
whatever the arm does, so that runs of different controllers meet the same pushes.
The record is a zero-order hold, as :func:~skelarm.control.simulate_controlled
applies a force: the sample recorded at t_k acts over [t_k, t_k+1). The last
sample marks the end of the record, as a run's final frame does, so no force acts
from it on, nor before the first sample. Replaying a run's own force with its own
controller and step therefore reproduces its motion and every force it applied
exactly, but not the force its final frame records, which no step applied: the
replay's final frame records none.
Example::
log = StateLog.load("pushed.sklog.npz")
pushes = RecordedForce.from_log(log)
again = simulate_controlled(skeleton, controller, duration=2.0, dt=0.002, external_force=pushes)
With a step other than the recording's, :meth:RecordedForce.stepped gives each step
the mean recorded force over it, which keeps every push's impulse.
RecordedForce
A recorded tip force, replayed by time as an external force.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
ArrayLike
|
The sample times (s), increasing; at least two. |
required |
forces
|
ArrayLike
|
The tip force |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the times do not increase, or the forces are not one |
Source code in src/skelarm/forces.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
start
property
The time of the first sample (s), from which the record acts.
stop
property
The time of the last sample (s), the end of the record.
__call__(t, skeleton=None)
The recorded force acting at time t, as simulate_controlled's external_force.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The time (s). |
required |
skeleton
|
Skeleton | None
|
The arm's state, which a recorded force does not depend on. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The tip force |
Source code in src/skelarm/forces.py
from_log(log, channel='ext_force', time_offset=0.0)
classmethod
Take the recorded force of a log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log
|
StateLog
|
A recorded run with a tip force channel. |
required |
channel
|
str
|
The channel to replay, |
'ext_force'
|
time_offset
|
float
|
Added to every sample time (s), to replay the log on another clock. |
0.0
|
Returns:
| Type | Description |
|---|---|
RecordedForce
|
The log's force history. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the log has no such channel. |
Source code in src/skelarm/forces.py
mean(begin, end)
The mean recorded force over [begin, end), each sample weighed by how long it acts within it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
begin
|
float
|
The interval (s), |
required |
end
|
float
|
The interval (s), |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The mean tip force |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/skelarm/forces.py
spans(threshold, min_gap=0.0)
When the force acts: the spans of time its magnitude exceeds threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The magnitude (N) above which the force counts as acting. |
required |
min_gap
|
float
|
Spans separated by less than this (s) are joined into one, so that a push that lulls for a moment counts once. |
0.0
|
Returns:
| Type | Description |
|---|---|
list[tuple[float, float]]
|
Each span's |
Source code in src/skelarm/forces.py
stepped(dt)
An external force for a simulation that steps by dt: the mean recorded force over each step.
A step [t, t + dt) gets the mean of the record over it, so every push keeps its
impulse whatever the step. With the recording's own step, aligned with its
samples, each step gets its sample exactly, as :meth:__call__ gives it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
The simulation step (s). |
required |
Returns:
| Type | Description |
|---|---|
Callable[[float, Skeleton], NDArray[float64]]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |