Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

MotionHook Class Reference

Interface for connections to remote hosts and hardware devices which should be polled with output values. More...

#include <MotionHook.h>

Inheritance diagram for MotionHook:

Detailed Description

Interface for connections to remote hosts and hardware devices which should be polled with output values.

  • Override motionCheck() if your hardware needs to have a value specified for every output on every update, regardless of whether it changes.
  • Override motionUpdated() if you only need to process the outputs which have changed.

You can expect to be called every FrameTime*NumFrame milliseconds in terms of simulator time. However, keep in mind this is relative to SharedGlobals::timeScale (Config.Speed) in terms of wall-clock time, and is also subject to the simulator being paused, set to full-speed mode, or hitting a breakpoint in the debugger. See enteringRealtime() and leavingRealtime() if you want updates when the user switches simulation modes, although there's still no way to get notification if a debugger breakpoint is hit.

Definition at line 23 of file MotionHook.h.

List of all members.

Classes

struct  PIDUpdate
 used as input to updatePIDs() More...

Public Member Functions

 MotionHook ()
 constructor
virtual ~MotionHook ()
 no-op destructor
virtual void motionStarting ()
 Called when motion process is starting.
virtual bool isConnected ()=0
 Should return true if the MotionHook is successfully connected to physical hardware.
virtual void motionCheck (const float outputs[][NumOutputs])
 Called each time the motion process has polled active motion commands.
virtual void motionUpdated (const std::vector< size_t > &, const float[][NumOutputs])
 Called by motionCheck(), after comparing the new output values to lastOutputs, and before lastOutputs is updated.
virtual void updatePIDs (const std::vector< PIDUpdate > &pids)
 Called when PID values change.
virtual void motionStopping ()
 Called when motion process is stopping.
virtual void enteringRealtime (const plist::Primitive< double > &)
 Called when the controller is going to be running in realtime mode, which is probably the normal mode you'd expect.
virtual void leavingRealtime (bool)
 Called when leaving realtime mode, which means you have no idea when motionCheck() is going to be called in terms of wall-clock time.
virtual void setMotionHookVerbose (int v)
 Called by simulator thread to indicate level of verbosity for diagnostics and reporting errors.

Protected Attributes

int verbose
 stores current verbosity
bool isFirstCheck
 set to false following the first motionCheck, reset to true by motionStopping
float lastOutputs [NumOutputs]
 stores the last frame of the outputs, updated by motionCheck()

Constructor & Destructor Documentation

MotionHook (  ) 

constructor

Definition at line 36 of file MotionHook.h.

virtual ~MotionHook (  )  [virtual]

no-op destructor

Definition at line 39 of file MotionHook.h.


Member Function Documentation

virtual void enteringRealtime ( const plist::Primitive< double > &   )  [virtual]

Called when the controller is going to be running in realtime mode, which is probably the normal mode you'd expect.

You might be in realtime mode, but a debugger breakpoint will still pause things, or thread scheduling could hiccup, so try to be robust.
The argument is a reference to SharedGlobals::timeScale, so the data source can subscribe to changes in simulation speed if it can use that information. (We avoid direct dependency on the tekkotsu simulator so this code can be reused for other tools too.)

Reimplemented in CreateDriver, DynamixelDriver, KobukiDriver, SkewlZoneDriver, and SSC32Driver.

Definition at line 106 of file MotionHook.h.

Referenced by Simulator::plistCollectionEntriesChanged(), Simulator::plistCollectionEntryAdded(), and Simulator::setMotionEnteringRealtime().

virtual bool isConnected (  )  [pure virtual]

Should return true if the MotionHook is successfully connected to physical hardware.

If relevant, this will only be called after motionStarting() has been called in order to initialize a connection.

This is used mainly to cancel out of the WaitForSensors if all MotionHooks return false. If you are still in the process of connecting or unsure of status, be optimistic and return true. This function will be polled at a coarse rate while blocked on sensors in case of timeouts on the part of the MotionHook render it moot.

Implemented in CreateDriver, DynamixelDriver, KobukiDriver, MirageDriver, SkewlZoneDriver, SSC32Driver, and IPCMotionHook.

Referenced by Simulator::run().

virtual void leavingRealtime ( bool   )  [virtual]

Called when leaving realtime mode, which means you have no idea when motionCheck() is going to be called in terms of wall-clock time.

Argument set to true if entering full speed mode, which may mean motionCheck will be called at a high(er) frequency, or slower the computation is overwhelming the host hardware. However, if false, almost certainly indicates updates will be sparse. May be called multiple times if changing between full-speed mode and paused

A non-realtime mode might be triggered if the user wants to pause the simulator/controller to step through something... No guarantees though! The debugger might catch a breakpoint and stop things, and this won't be called!

Reimplemented in CreateDriver, DynamixelDriver, KobukiDriver, SkewlZoneDriver, and SSC32Driver.

Definition at line 116 of file MotionHook.h.

Referenced by Simulator::plistCollectionEntriesChanged(), Simulator::plistCollectionEntryAdded(), Simulator::plistCollectionEntryRemoved(), and Simulator::setMotionLeavingRealtime().

virtual void motionCheck ( const float  outputs[][NumOutputs]  )  [virtual]

Called each time the motion process has polled active motion commands.

When in realtime mode, this should be called every FrameTime*NumFrames (defined in the RobotInfo) milliseconds if running at full speed. See enteringRealtime() and leavingRealtime().

This default implementation checks to see which outputs have changed value since the last call and passes the summary on to motionUpdated(). lastOutputs will be updated with the new values after the call to motionUpdated().

If you need to process all the outputs on every frame, you only need to override this function. Your subclass doesn't need to call the MotionHook implementation unless you want to have lastOutputs updated for you.

If you only need to process the changed outputs for each frame, override motionUpdated() instead. motionUpdated() is always called for each update, even if there aren't any changes, so you can still use that if there are some outputs which need to be updated every cycle.

Reimplemented in CreateDriver, DynamixelDriver, KobukiDriver, SkewlZoneDriver, SSC32Driver, and IPCMotionHook.

Definition at line 69 of file MotionHook.h.

Referenced by Simulator::updateMotion().

virtual void motionStarting (  )  [virtual]
virtual void motionStopping (  )  [virtual]

Called when motion process is stopping.

Reimplemented in CreateDriver, DynamixelDriver, KobukiDriver, MirageDriver, SkewlZoneDriver, SSC32Driver, and WiiMoteDriver.

Definition at line 99 of file MotionHook.h.

Referenced by Simulator::plistCollectionEntryRemoved(), and Simulator::setMotionStopping().

virtual void motionUpdated ( const std::vector< size_t > &  ,
const   float[][NumOutputs] 
) [virtual]

Called by motionCheck(), after comparing the new output values to lastOutputs, and before lastOutputs is updated.

Override this if you only need to send commands to the hardware for values that have changed. This function is always called for each update, even though changedIndices might be empty.

Reimplemented in MirageDriver, and WiiMoteDriver.

Definition at line 93 of file MotionHook.h.

Referenced by motionCheck().

virtual void setMotionHookVerbose ( int  v  )  [virtual]

Called by simulator thread to indicate level of verbosity for diagnostics and reporting errors.

Definition at line 119 of file MotionHook.h.

virtual void updatePIDs ( const std::vector< PIDUpdate > &  pids  )  [virtual]

Called when PID values change.

Reimplemented in DynamixelDriver, and IPCMotionHook.

Definition at line 96 of file MotionHook.h.

Referenced by Simulator::updatePIDs().


Member Data Documentation

bool isFirstCheck [protected]

set to false following the first motionCheck, reset to true by motionStopping

Definition at line 125 of file MotionHook.h.

Referenced by SSC32Driver::advance(), SSC32Driver::motionCheck(), motionCheck(), and motionStopping().

float lastOutputs[NumOutputs] [protected]

stores the last frame of the outputs, updated by motionCheck()

Definition at line 127 of file MotionHook.h.

Referenced by SSC32Driver::motionCheck(), and motionCheck().

int verbose [protected]

stores current verbosity

Definition at line 123 of file MotionHook.h.

Referenced by SSC32Driver::motionCheck(), CreateDriver::sendCommand(), and setMotionHookVerbose().


The documentation for this class was generated from the following file:

Tekkotsu Hardware Abstraction Layer 5.1CVS
Generated Mon May 9 05:01:41 2016 by Doxygen 1.6.3