Class RB8904
/*
D_RB8904.HPP
Header file for RB8904 driver.
(Dual Stepping Motor Controller)
Copyright (C), 1992 by Rijksuniversiteit Leiden.
Version: 0.04
Date : 2 Mar 1992
Disk : ruldev\inc\ruldev
Author : M.J. Moene
Compiler : Borland C++ 2.0
Operating system: MS-DOS 3.21
Hardware system : PC XT, AT
*/
#ifndef __D_RB8904_HPP // already included?
#define __D_RB8904_HPP
#ifndef __D_RULBUS_HPP // already included?
#include <ruldev\d_rulbus.hpp>
#endif
#define DEF_NAME "RB8904" // default device name
#define DEF_MOTR 1 // default motor number
#define DEF_ADDR 0xB4 // default device address
class RB8904 : public Rulbus // derived from Rulbus
{
public:
~RB8904(); // destructor
RB8904( const char *name = DEF_NAME, // constructor
int motr = DEF_MOTR,
int addr = DEF_ADDR,
int rack = DEF_RACK,
int base = DEF_BASE );
Boolean busy (Status& status = Ok);
Status wait ();
Status calibrate (Boolean and_wait = false);
unsigned long getPosition (Status& status = Ok);
Status putPosition (unsigned long position,
Boolean and_wait = false);
int getTimePerStep (Status& status = Ok);
Status putTimePerStep (int time );
unsigned long getStepPerTrigger (Status& status = Ok);
Status putStepPerTrigger (unsigned long trigger);
Boolean interruptPending (Status& status = Ok);
Boolean getInterruptState (Status& status = Ok);
Boolean putInterruptState (Boolean enable,
Status& status = Ok);
Boolean enableInterrupt (Status& status = Ok);
Boolean disableInterrupt (Status& status = Ok);
void dialog () ; // virtual dialog
classType isA () const; // type info
char *nameOf () const; // type info
protected:
int getMotor ();
Status putMotor (int mtr);
Boolean isInvalidMTR (int mtr);
Boolean isInvalidPOS (unsigned long pos);
Boolean isInvalidTPS (int tps);
Boolean isInvalidSPT (unsigned long spt);
unsigned long read (const char *fn, int cmd, unsigned long def, Status& status);
Status write (const char *fn, int cmd, signed long val = -1 );
Status _scan (istream &is = cin ); // scan object
Status _print (ostream &os = cout); // print object
private:
int motor; // motor number for this instance
Boolean intState; // interrupt enable state
unsigned long savedPos; // saved destination position
enum // communication codes
{
COM_RDY = 0, // ready code
COM_GET = 1, // get character code
COM_EOT = 2, // end-of-transmission code
COM_LEN = 15, // maximum string length
COM_TIM = 5000, // # retries for communication
};
const char *cmdString (int cmd);
int getCharacter ();
int putCharacter (char ch);
const char *getString (char *string, int maxlen = COM_LEN);
int putString (const char *string );
};
class RB8904A : public RB8904 // derived from standard RB8904
{
public:
~RB8904A(); // destructor
RB8904A(const char *name = DEF_NAME, // constructor
int motr = DEF_MOTR,
int addr = DEF_ADDR,
int rack = DEF_RACK,
int base = DEF_BASE );
unsigned long getStepPerSweep (Status& status = Ok);
Status putStepPerSweep (unsigned long steps);
Boolean getSweepState (Status& status = Ok);
Boolean putSweepState (Boolean enable,
Status& status = Ok);
Boolean enableSweep (Status& status = Ok);
Boolean disableSweep (Status& status = Ok);
void dialog () ; // dialog
classType isA () const; // type info
char *nameOf () const; // type info
protected:
Status checkMotor2 (const char *fn ); // check with error trap
Boolean isInvalidSPS (unsigned long sps); // check step per sweep
Status _scan (istream &is = cin ); // scan object
Status _print (ostream &os = cout); // print object
};
#undef DEF_NAME // undefine device
#undef DEF_MOTR // undefine motor
#undef DEF_ADDR // undefine rulbus address
#endif // ifndef __D_RB8904_HPP
/*** End of file ***/
-----------------------------------------------------------------------------
RB8904 - Dual Stepping Motor Controller
-----------------------------------------------------------------------------
Class RB8904
Derived from Rulbus (ruldev library)
Remarks Module RB8904 is a dual stepping motor controller.
The controller has two stepping motor outputs that provide
the following signals:
- stepping motor signals,
- trigger output,
- begin stop input,
- end stop input.
Via the Rulbus the following can be programmed and read back:
- motor position,
- number of ms per step,
- number of steps per trigger,
- Rulbus trigger interrupt enable state,
- the Rulbus interrupt state can be read.
For each motor, you should define a separate instance e.g.:
RB8904 motor1("motor1", 1);
RB8904 motor2("motor2", 2);
Class RB8904 provides functions to:
- check if the motor is at it's destination position,
- wait for the motor to reach it's destination position,
- start a calibration,
- get and set the destination position,
- get and set the time per step value,
- get and set the number of steps per trigger value,
- check if an trigger interrupt is pending,
- enable or disable the trigger interrupt.
-----------------------------------------------------------------------------
constructor RB8904
-----------------------------------------------------------------------------
Function construct an instance of class RB8904
Syntax #include <ruldev\d_rb8904.hpp>
RB8904::RB8904(const char *name, int motr, int addr, int rack, int base);
Prototype in d_rb8904.hpp
Remarks this is the constructor for class RB8904.
When an invalid motor number is specified for mtr, the
constructor executes the fatal error trap routine with
error code BadValue and message `constructor'.
The default state for this device is:
- motor number is 1,
- position is 0,
- time per step is at minimum
(this depends on the controller software version/motor used),
- steps per trigger is 1,
- interrupt is disabled,
Arguments name: name of instance (default: "RB8904")
motr: motor number (1 or 2) (default: 1)
addr: rulbus address of instance (default: 0xB4)
rack: rulbus rack number (default: 0)
base: rulbus converter address (default: 0x200)
Return Value none.
-----------------------------------------------------------------------------
destructor RB8904
-----------------------------------------------------------------------------
Function destruct an instance of class RB8904
Syntax #include <ruldev\d_rb8904.hpp>
RB8904::~RB8904();
Prototype in d_rb8904.hpp
Remarks this is the destructor for class RB8904
Arguments none none
Return value none.
------------------------------------------------------------------------------
isA RB8904
------------------------------------------------------------------------------
Function return type information.
Syntax #include <ruldev\d_rb8904.hpp>
virtual classType RB8904::isA() const;
Prototype in d_rulbus.hpp
Remarks isA returns CLS_RB8904 to uniquely identify this class.
Arguments none
Return value CLS_RB8904
------------------------------------------------------------------------------
nameOf RB8904
------------------------------------------------------------------------------
Function return the type name of this device instance.
Syntax #include <ruldev\d_rb8904.hpp>
virtual char *RB8904::nameOf() const;
Prototype in d_rb8904.hpp
Remarks nameOf returns a string representation of the name
of this type.
Arguments none
Return value "RB8904".
-------------------------------------------------------------------------------
busy RB8904
-------------------------------------------------------------------------------
Function check if motor is running.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::busy(Status& status = Ok);
Prototype in d_rb8904.hpp
Remarks busy checks if the motor is running.
It returns true if the motor is running, false if the motor
is at the destination position.
busy passes back Timeout to status if the communication
with the controller failed and returns false, otherwise it
passes back Ok to status.
Arguments status: Ok, Timeout (optional).
Return value true, false (motor running, motor at destination or error).
-------------------------------------------------------------------------------
wait RB8904
-------------------------------------------------------------------------------
Function wait until motor is at destination position.
Syntax #include <ruldev\d_rb8904.hpp>
Status RB8904::wait();
Prototype in d_rb8904.hpp
Remarks wait waits until the motor is at the destination position.
It returns Timeout if communication with the controller
failed, otherwise it returns Ok.
Arguments none
Return value Ok, Timeout.
-------------------------------------------------------------------------------
calibrate RB8904
-------------------------------------------------------------------------------
Function define the motor start-position.
Syntax #include <ruldev\d_rb8904.hpp>
Status RB8904::calibrate(Boolean and_wait = false);
Prototype in d_rb8904.hpp
Remarks calibrate (re)defines the motor start-position (0).
The motor is running reverse until the begin-stop is
reached and the motor position is reset to 0.
When and_wait is true, calibrate waits until the motor
calibration is completed, otherwise it returns immediately
after the calibrate command is sent to the controller.
calibrate returns Timeout when communication with the
controller failed, otherwise it returns Ok.
Arguments and_wait: true, false (default: false).
Return value Ok, Timeout.
-----------------------------------------------------------------------------
getPosition RB8904
-----------------------------------------------------------------------------
Function get the current motor position
Syntax #include <ruldev\d_rb8904.hpp>
unsigned long RB8904::getPosition(Status& status = Ok);
Prototype in d_rb8904.hpp
Remarks getPosition returns the current motor position.
It passes back Timeout to status if communication with the
controller failed and returns 0, otherwise it passes back Ok
to status and returns the current motor position.
Arguments status: Ok, Timeout (optional).
Return value motor position (0..16777215), or 0 on error.
-----------------------------------------------------------------------------
putPosition RB8904
-----------------------------------------------------------------------------
Function define a new destination position.
Syntax #include <ruldev\d_rb8904.hpp>
Status RB8904::putPosition(unsigned long position, Boolean and_wait = false);
Prototype in d_rb8904.hpp
Remarks putPosition writes the specified position to the stepping
motor controller. If and_wait is true putPosition waits
for the motor to reach its destination position, if it's
false putPosition returns immediately.
If the specified position is invalid, putPosition returns
BadValue, else if communication with the controller failed,
it returns Timeout, otherwise it returns Ok.
Arguments position: 0..16777215,
and_wait: true, false (wait, no wait) (default: false).
Return value Ok, BadValue, Timeout.
-----------------------------------------------------------------------------
getTimePerStep RB8904
-----------------------------------------------------------------------------
Function get the current time per step in ms.
Syntax #include <ruldev\d_rb8904.hpp>
int RB8904::getTimePerStep(Status& status = Ok);
Prototype in d_rb8904.hpp
Remarks getTimePerStep returns the current time per step value in ms.
It passes back Timeout to status if communication with the
controller failed and returns 0, otherwise it passes back Ok
to status and returns the current time per step value.
Arguments status : Ok, Timeout (optional).
Return value time per step (1..255), or 0 on error.
-----------------------------------------------------------------------------
putTimePerStep RB8904
-----------------------------------------------------------------------------
Function define the time per step setting in ms.
Syntax #include <ruldev\d_rb8904.hpp>
Status RB8904::putTimePerStep(int time);
Prototype in d_rb8904.hpp
Remarks putTimePerStep writes the specified time per step value
to the stepping motor controller.
When 0 is specified for time, the time per step value is
set to the minimum value possible. This value is determined
by the controller software version.
If the specified time is invalid, putTimePerStep returns
BadValue, else if communication with the controller failed,
it returns Timeout, otherwise it returns Ok.
Arguments time: 0..255.
Return value Ok, BadValue, Timeout.
-----------------------------------------------------------------------------
getStepPerTrigger RB8904
-----------------------------------------------------------------------------
Function get the current number of steps per trigger pulse.
Syntax #include <ruldev\d_rb8904.hpp>
unsigned long RB8904::getStepPerTrigger(Status& status = Ok);
Prototype in d_rb8904.hpp
Remarks getStepPerTrigger returns the current step per trigger value.
It passes back Timeout to status if communication with the
controller failed and returns 0, otherwise it passes back Ok
to status and returns the current time per step value.
Arguments status : Ok, Timeout (optional).
Return value steps per trigger (1..16777215), or 0 on error.
-----------------------------------------------------------------------------
putStepPerTrigger RB8904
-----------------------------------------------------------------------------
Function define the number of steps per trigger setting.
Syntax #include <ruldev\d_rb8904.hpp>
Status RB8904::putStepPerTrigger(unsigned long steps);
Prototype in d_rb8904.hpp
Remarks putStepPerTrigger writes the specified step per trigger value
to the stepping motor controller.
If the specified step value is invalid, putStepPerTrigger
returns BadValue, else if communication with the controller
failed, it returns Timeout, otherwise it returns Ok.
Arguments steps: 1..16777215.
Return value Ok, BadValue, Timeout.
-----------------------------------------------------------------------------
interruptPending RB8904
-----------------------------------------------------------------------------
Function check if a Rulbus trigger interrupt is pending.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::interruptPending(Status& status = Ok);
Prototype in d_rb8904.hpp
Remarks interruptPending returns true if a trigger interrupt is
pending, false otherwise.
It passes back Timeout to status if communication with the
controller failed, otherwise it passes back Ok to status.
Arguments status : Ok, Timeout (optional).
Return value true, false (interrupt pending, not pending).
-----------------------------------------------------------------------------
getInterruptState RB8904
-----------------------------------------------------------------------------
Function get the current Rulbus trigger interrupt enable state.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::getInterruptState(Status& status = Ok);
Prototype in d_rb8904.hpp
Remarks getInterruptState returns the current trigger interrupt
enable state.
It passes back Timeout to status if communication with the
controller failed, otherwise it passes back Ok.
Arguments status : Ok, Timeout (optional).
Return value true, false (enabled, disabled or error).
-------------------------------------------------------------------------------
putInterruptState RB8904
-------------------------------------------------------------------------------
Function define the Rulbus trigger interrupt enable state.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::putInterruptState(Boolean enable, Status& status = Ok);
Prototype in d_rb8904.hpp
Remarks putInterruptState enables the trigger interrupt if enable
is true, or disables it when enable is false.
It passes back Timeout to status if communication with the
controller failed, otherwise it passes back Ok.
putInterruptState returns the previous trigger interrupt
enable state.
Arguments enable: true, false (enable, disable),
status: Ok, Timeout (optional).
Return value previous trigger interrupt enable state.
-----------------------------------------------------------------------------
enableInterrupt RB8904
-----------------------------------------------------------------------------
Function enable the Rulbus trigger interrupt.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::enableInterrupt(Status& status = Ok);
Prototype in d_rb8904.hpp
Remarks enableInterrupt enables the trigger interrupt.
It passes back Timeout to status if communication with the
controller failed, otherwise it passes back Ok.
enableInterrupt returns the previous trigger interrupt
enable state.
Arguments status : Ok, Timeout (optional).
Return value previous trigger interrupt enable state.
-----------------------------------------------------------------------------
disableInterrupt RB8904
-----------------------------------------------------------------------------
Function disable the Rulbus trigger interrupt.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::disableInterrupt(Status& status = Ok);
Prototype in d_rb8904.hpp
Remarks disableInterrupt disables the trigger interrupt.
It passes back Timeout to status if communication with the
controller failed, otherwise it passes back Ok.
disableInterrupt returns the previous trigger interrupt
enable state.
Arguments status : Ok, Timeout (optional).
Return value previous trigger interrupt enable state.
-------------------------------------------------------------------------------
(getMotor) RB8904
-------------------------------------------------------------------------------
Function return the motor numer.
Syntax #include <ruldev\d_rb8904.hpp>
int RB8904::getMotor();
Prototype in d_rb8904.hpp
Remarks getMotor returns the motor number of this instance.
Arguments none
Return value 1, 2.
-------------------------------------------------------------------------------
(putMotor) RB8904
-------------------------------------------------------------------------------
Function select the motor number.
Syntax #include <ruldev\d_rb8904.hpp>
Status RB8904::putMotor(int motor);
Prototype in d_rb8904.hpp
Remarks putMotor sets the active motor for this instance to mtr if
it is valid. If the specified motor number is invalid, putMotor
returns BadValue, otherwise it returns Ok.
Arguments motor: 1, 2.
Return value Ok, BadValue.
-------------------------------------------------------------------------------
(isInvalidMTR) RB8904
-------------------------------------------------------------------------------
Function check if specified motor number is valid.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::isInvalidMTR(int motor);
Prototype in d_rb8904.hpp
Remarks isInvalidMTR returns true if the motor number specified
is invalid, otherwise it returns false.
Arguments motor: 1, 2.
Return value true, false (not valid, valid).
-------------------------------------------------------------------------------
(isInvalidPOS) RB8904
-------------------------------------------------------------------------------
Function check if specified position is valid.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::isInvalidPOS(unsigned long position);
Prototype in d_rb8904.hpp
Remarks isInvalidPOS returns true if the position specified
is invalid, otherwise it returns false.
Arguments position: 0..16777215.
Return value true, false (not valid, valid).
-------------------------------------------------------------------------------
(isInvalidTPS) RB8904
-------------------------------------------------------------------------------
Function check if specified number of time per step is valid.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::isInvalidTPS(int time);
Prototype in d_rb8904.hpp
Remarks isInvalidTPS returns true if the time per step specified
is invalid, otherwise it returns false.
Arguments time: 0..16777215.
Return value true, false (not valid, valid).
-------------------------------------------------------------------------------
(isInvalidSPT) RB8904
-------------------------------------------------------------------------------
Function check if specified number of steps per trigger is valid.
Syntax #include <ruldev\d_rb8904.hpp>
Boolean RB8904::isInvalidSPT(unsigned long steps);
Prototype in d_rb8904.hpp
Remarks isInvalidSPT returns true if the steps per trigger specified
is invalid, otherwise it returns false.
Arguments steps: 1..16777215.
Return value true, false (not valid, valid).
-------------------------------------------------------------------------------
(read) RB8904
-------------------------------------------------------------------------------
Function read a value from the controller.
Syntax #include <ruldev\d_rb8904.hpp>
unsigned long RB8904::read(const char* fn, int cmd, unsigned long def, Status& status);
Prototype in d_rb8904.hpp
Remarks read writes the command string corresponding to code `cmd'
to the controller, obtains the response and returns it.
read passes back Timeout to status if communication with
the controller failed and returns the value of `def',
otherwise it passes back Ok to status and returns the
response to the command issued.
Arguments fn : name of calling function,
cmd : command code,
def : default return value on error,
status: status passed back (Ok, Timeout).
Return value value read, or value of `def' on error.
-------------------------------------------------------------------------------
(write) RB8904
-------------------------------------------------------------------------------
Function write a command and optional value to the controller.
Syntax #include <ruldev\d_rb8904.hpp>
Status RB8904::write(const char *fn, int cmd, signed long val = -1);
Prototype in d_rb8904.hpp
Remarks write writes the command string corresponding to code `cmd'
and a optional value to the controller. write returns Timeout
if communication with the controller failed, otherwise it
returns Ok.
Arguments fn : name of calling function,
cmd: command code,
val: value to write (optional: -1, meaning no value).
Return value Ok, Timeout.
-------------------------------------------------------------------------------
(_scan) RB8904
-------------------------------------------------------------------------------
Function initialize the device from a stream.
Syntax #include <ruldev\d_rb8904.hpp>
virtual Status RB8904::_scan(istream &is = cin);
Prototype in d_rb8904.hpp
Remarks _scan reads the device representation as created by _print
and initializes the device with these settings. _scan returns
Ok when it properly read the object, otherwise it returns
BadRecord if the record read was not for this device, or
BadInput if a stream input error occurred.
See also Device::print.
Arguments is: reference to the input stream (default: cin)
Return value Ok, BadRecord, BadInput.
-------------------------------------------------------------------------------
(_print) RB8904
-------------------------------------------------------------------------------
Function write an initialization record for this object to a stream.
Syntax #include <ruldev\d_rb8904.hpp>
virtual Status RB8904::_print(ostream &os = cout);
Prototype in d_rb8904.hpp
Remarks _print writes a device represention to a stream from which
_scan can initialize the device. _print returns Ok when it
properly wrote the object, otherwise it returns BadOutput
if a stream write error occurred. See also Device::print.
Arguments os: reference to the output stream (default: cout)
Return value Ok, BadOutput.