📄 executive.h
字号:
/*--------------------------------------------------*
* Executive.h: *
* C++ DML controller, robot executive thread *
*--------------------------------------------------*
#pragma warning( disable : 4514 4001 4201 4214 )
#pragma warning( disable : 4115)
#include <windows.h>
#pragma warning( default : 4115)
#include <assert.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <math.h>
#include <stdio.h>
#include "dml.h"
#include "dmlchanref.h"
#include "dmlcontroller.h"
#include "DMLMonitorInclude.h"
#include "PMDInterface.h"
#include <queue>
// Constants used by Executive:
const int ciDefaultControllerServicePeriod = 100; // ms
// List of all the commands that another thread can ask Executive to execute:
enum CommandID
{
CmdCommit,
CmdZeroPosition,
CmdSCurveMove,
CmdTrapezoidalMove,
CmdVelocityMove,
CmdSmoothStop,
CmdAbruptStop,
CmdSetAcceleration,
CmdSetJerk,
CmdSetPowerLevel,
CmdSetLeftVelocity,
CmdSetRightVelocity,
CmdSetLeftMoveDistance,
CmdSetRightMoveDistance,
CmdResetEventStatus
};
// Executive, our primary DML Controller thread
class Executive : public DMLController, ChannelMonitor
{
public:
Executive();
STATUS CreateChannels();
STATUS CreateMonitors();
void StartService();
void Service();
STATUS ProcessStringCommand(HWND hWndSource, char *pszStringCommand);
void TerminateService();
STATUS DestroyChannels();
// Allow robot behaviors to send commands to the Executive for processing
void EnqueueCommand(CommandID Cmd);
void ExecuteCommand(CommandID Cmd);
void ClearCommandQueue();
void SetMotionDefaults(); // reset velocity, acceleration, deceleration to default values
void AdjustPowerLevel(int PowerLevel); // Change the power level
void ResetVelocity(); // reset velocity to default value (needed after a Stop)
void MoveForward(int mmDistance); // command a forward move
void Turn(int degreesAngle); // positive angle = left turn (counterclockwise rotation),
// negative angle = right turn (clockwise rotation)
double GetMoveProgress(); // return what fraction of the move has completed so far (0.0 to 1.0)
bool RobotInMotion(); // is the robot moving? (checks Activity Status)
private:
// ReceiveUpdate() handles all data change callbacks for Executive:
void ReceiveUpdate(DML_ChannelRef *pChan, DML_Data &NewData);
void Move(int mmLeftDistance, int mmRightDistance);
PMD_Axis *m_pLeft;
PMD_Axis *m_pRight;
DML_TIME m_CountStartTime;
int m_ServiceCount;
CRITICAL_SECTION m_QueueLock;
CRITICAL_SECTION m_PMDLock;
queue<CommandID> m_CommandQueue;
};
extern Executive *gController; // declared in Executive.cpp
// Robot control and status readback channels (allow Behavior.cpp to access these)
extern DML_ChannelRef *gIRLeftSide;
extern DML_ChannelRef *gIRRightSide;
extern DML_ChannelRef *gIRForward;
extern DML_ChannelRef *gIRLeft30;
extern DML_ChannelRef *gIRRight30;
extern DML_ChannelRef *gIRBeakDownLeft;
extern DML_ChannelRef *gIRBeakDownCenter;
extern DML_ChannelRef *gIRBeakDownRight;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -