INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

NONFRAMEWORK CODE
Driver Interfaces
Drivers
Libraries
Utilities

FRAMEWORK CODE
Interfaces
Components
Libraries
Utilities

Full Software Listings

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

message.h

00001 /*************************************************************************
00002         
00003         date            : August 2008
00004         copyright       : (C) 2005 J.D. Yamokoski
00005         email   : yamokosk+gnu at gmail dot com
00006 
00007  This library is free software; you can redistribute it and/or
00008  modify it under the terms of the GNU Lesser General Public License as
00009  published by the Free Software Foundation; either version 2.1 of the License,
00010  or (at your option) any later version. The text of the GNU Lesser General
00011  Public License is included with this library in the file LICENSE.TXT.
00012  
00013  This library is distributed in the hope that it will be useful, but WITHOUT
00014  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015  or FITNESS FOR A PARTICULAR PURPOSE. See the file LICENSE.TXT for
00016  more details.
00017  
00018  *************************************************************************/
00019 
00020 #ifndef HYDRO_MHI_PA10_ARCNET_MESSAGE_H_
00021 #define HYDRO_MHI_PA10_ARCNET_MESSAGE_H_
00022 
00023 #include <sys/types.h>
00024 #include <stdint.h>
00025 #include <string.h>
00026 #include <memory>
00027 
00028 #include <hydrointerfaces/mhipa10.h>
00029 #include <IceUtil/IceUtil.h>    // for time functions
00030 #include <hydroiceutil/timeutils.h>
00031 
00032 #include "model.h"
00033 
00034 namespace mhipa10arc
00035 {
00036 
00037 /*
00038   MHI command messages consist of:
00039     - Header (6 bytes)
00040     - Data (250 bytes of which a variable amount is used depending on packet type)
00041 
00042   @author J.D. Yamokoski
00043 */
00044 class Message
00045 {
00046 public:
00047         // Always use all 256 bytes
00048         static const int max_msg_length = 256;
00049         // Frame counter
00050         static uint8_t frame_count;
00051 
00052         // Packet header
00053         struct Header
00054         {
00055                 uint8_t sender;
00056                 uint8_t receiver;
00057                 uint8_t frameNumberAddr;
00058                 uint8_t junkVal;
00059                 uint8_t frameNumber;
00060                 uint8_t msgType;
00061         };
00062 
00063         Message(unsigned int length);
00064 
00065         // Returns who create this message
00066         uint8_t sender() {return msg_[0];}
00067         // Returns who this message was sent to
00068         uint8_t receiver() {return msg_[1];}
00069         // Returns the message frame count
00070         uint8_t frameNumber() {return msg_[4];}
00071         // Returns the message type
00072         uint8_t messageType() {return msg_[5];}
00073         // Returns the actual message length = header + data
00074         unsigned int length() {return message_length_;}
00075 
00076         // Allow direct access for memcpy
00077         uint8_t* msg() { return msg_; }
00078         const uint8_t *msg() const { return msg_; }
00079 
00080         // Human-readable string for debugging
00081         std::string toString() const;
00082 
00083         // Get/set timestamp
00084         void timeStamp();
00085         IceUtil::Time getTimeStamp() const {return timeStamp_;}
00086         
00087 private:
00088         uint8_t msg_[max_msg_length];
00089         unsigned int message_length_;
00090         IceUtil::Time timeStamp_;
00091 };
00092 
00093 typedef std::auto_ptr<Message> MessagePtr;
00094 
00095 
00097 
00098 class MessageFactory
00099 {
00100 protected:
00101         MessagePtr msg_;
00102         uint8_t senderID_;
00103         uint8_t receiverID_;
00104 
00105 public:
00106         MessageFactory(uint8_t sender=0xFF, uint8_t receiver=0xFE) :
00107                 senderID_(sender), receiverID_(receiver) {}
00108         virtual ~MessageFactory() {}
00109 
00110         virtual MessagePtr createMessage();
00111 
00112 protected:
00113         virtual void writeHeader();
00114         virtual void writeMessage() = 0;
00115         virtual unsigned int length() = 0;
00116 };
00117 
00118 
00120 
00121 class MotionCommandFactory : public MessageFactory
00122 {
00123         static const uint16_t   BRAKE_BIT_MASK = 0x0001;
00124         static const uint16_t   SERVO_POWER_BIT_MASK = 0x0002;
00125         static const uint16_t   TORQUE_COMMAND_TYPE_BIT_MASK = 0x0004;
00126         static const uint16_t   OTHER_AXIS_ALARM_BIT_MASK = 0x0010;
00127 
00128         static const uint16_t   DEADMAN_SW_BIT_MASK = 0x0008;
00129 
00130         // Servo command format
00131         struct ServoMessage
00132         {
00133                 uint16_t        status;         // Status: brake ON/OFF, power ON/OFF, spd/trq command
00134                 int16_t         trqCmdVal;  // Commanded torque value
00135                 int16_t         spdCmdVal;      // Commanded joint speed
00136         } __attribute__((__packed__));
00137 
00138         // Arm command format
00139         struct ArmMessage
00140         {
00141                 ServoMessage    servoCmd[7];
00142                 uint16_t                commCPU;
00143         } __attribute__((__packed__));
00144 
00145         // Entire message - message plus header
00146         struct MessageFormat
00147         {
00148                 mhipa10arc::Message::Header hdr;
00149                 ArmMessage msg;
00150         } __attribute__((__packed__));
00151 
00152 public:
00153         MotionCommandFactory( const hydrointerfaces::MitsubishiPA10::ManipulatorCommand& cmd ) :
00154                 MessageFactory(), cmd_(cmd) {}
00155         MotionCommandFactory( uint8_t sender, uint8_t receiver, const hydrointerfaces::MitsubishiPA10::ManipulatorCommand& cmd ) :
00156                 MessageFactory(sender, receiver), cmd_(cmd) {}
00157         virtual ~MotionCommandFactory() {}
00158 
00159 protected:
00160         virtual void writeHeader();
00161         virtual void writeMessage();
00162         virtual unsigned int length();
00163         
00164         hydrointerfaces::MitsubishiPA10::ManipulatorCommand cmd_;
00165 };
00166 
00167 
00169 
00170 class AlarmClearFactory : public MessageFactory
00171 {
00172         // Entire packet - message plus header
00173         struct MessageFormat
00174         {
00175                 mhipa10arc::Message::Header hdr;
00176                 uint16_t axisNumber;
00177         } __attribute__((__packed__));
00178 
00179 public:
00180         AlarmClearFactory(uint16_t axisNumber) :
00181                 MessageFactory(), axisNumber_(axisNumber) {}
00182         AlarmClearFactory(uint8_t sender, uint8_t receiver, uint16_t axisNumber) :
00183                 MessageFactory(sender, receiver), axisNumber_(axisNumber) {}
00184         virtual ~AlarmClearFactory() {};
00185 
00186 protected:
00187         virtual void writeHeader();
00188         virtual void writeMessage();
00189         virtual unsigned int length();
00190 
00191 private:
00192         uint16_t axisNumber_;
00193 };
00194 
00195 
00197 
00198 class StartControlFactory : public MessageFactory
00199 {
00200 public:
00201         StartControlFactory() : MessageFactory() {}
00202         StartControlFactory(uint8_t sender, uint8_t receiver) : MessageFactory(sender, receiver) {}
00203         virtual ~StartControlFactory() {};
00204 
00205 protected:
00206         virtual void writeHeader();
00207         virtual void writeMessage();
00208         virtual unsigned int length();
00209 };
00210 
00211 
00213 
00214 class StartBrakeReleaseFactory : public MessageFactory
00215 {
00216 public:
00217         StartBrakeReleaseFactory() : MessageFactory() {}
00218         StartBrakeReleaseFactory(uint8_t sender, uint8_t receiver) : MessageFactory(sender, receiver) {}
00219         virtual ~StartBrakeReleaseFactory() {};
00220 
00221 protected:
00222         virtual void writeHeader();
00223         virtual void writeMessage();
00224         virtual unsigned int length();
00225 };
00226 
00227 
00229 
00230 class StopControlFactory : public MessageFactory
00231 {
00232 public:
00233         StopControlFactory() : MessageFactory() {}
00234         StopControlFactory(uint8_t sender, uint8_t receiver) : MessageFactory(sender, receiver) {}
00235         virtual ~StopControlFactory() {};
00236 
00237 protected:
00238         virtual void writeHeader();
00239         virtual void writeMessage();
00240         virtual unsigned int length();
00241 };
00242 
00243 } // namespace
00244 
00245 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5