YouBotSlaveMsg.hpp

Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2011
00004  * All rights reserved.
00005  *
00006  * Hochschule Bonn-Rhein-Sieg
00007  * University of Applied Sciences
00008  * Computer Science Department
00009  *
00010  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00011  *
00012  * Author:
00013  * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov
00014  * Supervised by:
00015  * Gerhard K. Kraetzschmar
00016  *
00017  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00018  *
00019  * This sofware is published under a dual-license: GNU Lesser General Public
00020  * License LGPL 2.1 and BSD license. The dual-license implies that users of this
00021  * code may choose which terms they prefer.
00022  *
00023  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00024  *
00025  * Redistribution and use in source and binary forms, with or without
00026  * modification, are permitted provided that the following conditions are met:
00027  *
00028  *     * Redistributions of source code must retain the above copyright
00029  *       notice, this list of conditions and the following disclaimer.
00030  *     * Redistributions in binary form must reproduce the above copyright
00031  *       notice, this list of conditions and the following disclaimer in the
00032  *       documentation and/or other materials provided with the distribution.
00033  *     * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its
00034  *       contributors may be used to endorse or promote products derived from
00035  *       this software without specific prior written permission.
00036  *
00037  * This program is free software: you can redistribute it and/or modify
00038  * it under the terms of the GNU Lesser General Public License LGPL as
00039  * published by the Free Software Foundation, either version 2.1 of the
00040  * License, or (at your option) any later version or the BSD license.
00041  *
00042  * This program is distributed in the hope that it will be useful,
00043  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00044  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00045  * GNU Lesser General Public License LGPL and the BSD license for more details.
00046  *
00047  * You should have received a copy of the GNU Lesser General Public
00048  * License LGPL and BSD license along with this program.
00049  *
00050  ****************************************************************/
00051 
00052 #ifndef _YOUBOT_SLAVE_MESSAGE_H
00053 #define _YOUBOT_SLAVE_MESSAGE_H
00054 
00055 #include "generic/dataobjectlockfree/DataObjectLockFree.hpp"
00056 #include <ethercattype.h>
00057 #include <string>
00058 #include <time.h>
00059 
00060 namespace youbot {
00061 
00062   /// Output part from the EtherCat message of the youBot EtherCat slaves
00063 
00064   struct SlaveMessageOutput {
00065     int32 value;
00066     uint8 controllerMode;
00067     SlaveMessageOutput():value(0),controllerMode(0) { };
00068   } __attribute__((__packed__));
00069 
00070 
00071   /// Input part from the EtherCat message of the youBot EtherCat slaves
00072 
00073   struct SlaveMessageInput {
00074     int32 actualPosition;   // encoder ticks
00075     int32 actualCurrent;    // mA
00076     int32 actualVelocity;   // rpm motor axis
00077     uint32 errorFlags;
00078     int32 targetPosition;
00079     int32 targetCurrent;
00080     int32 targetVelocity;
00081     int32 rampGeneratorVelocity;
00082 
00083     SlaveMessageInput():
00084     actualPosition(0),actualCurrent(0),actualVelocity(0),
00085     errorFlags(0),targetPosition(0),targetCurrent(0),
00086     targetVelocity(0),rampGeneratorVelocity(0) { };
00087   } __attribute__((__packed__));
00088 
00089   ///////////////////////////////////////////////////////////////////////////////
00090   /// EtherCat message of the youBot EtherCat slaves
00091   ///////////////////////////////////////////////////////////////////////////////
00092   class YouBotSlaveMsg {
00093   public:
00094 
00095 
00096     SlaveMessageOutput stctOutput;
00097     SlaveMessageInput stctInput;
00098     unsigned int jointNumber;
00099 
00100     // Constructor
00101 
00102     YouBotSlaveMsg() {
00103       jointNumber = 0;
00104     }
00105 
00106     // Copy-Constructor
00107 
00108     YouBotSlaveMsg(const YouBotSlaveMsg &copy) {
00109       stctOutput = copy.stctOutput;
00110       stctInput = copy.stctInput;
00111       jointNumber = copy.jointNumber;
00112     }
00113 
00114     // Destructor
00115 
00116     ~YouBotSlaveMsg() {
00117     }
00118 
00119     // assignment operator
00120 
00121     YouBotSlaveMsg & operator=(const YouBotSlaveMsg &copy) {
00122       stctOutput = copy.stctOutput;
00123       stctInput = copy.stctInput;
00124       jointNumber = copy.jointNumber;
00125       return *this;
00126     }
00127   };
00128   
00129   ///////////////////////////////////////////////////////////////////////////////
00130   /// EtherCat message of the youBot EtherCat slaves which is thread safe
00131   ///////////////////////////////////////////////////////////////////////////////
00132   class YouBotSlaveMsgThreadSafe {
00133   public:
00134 
00135 
00136     DataObjectLockFree<SlaveMessageOutput> stctOutput;
00137     DataObjectLockFree<SlaveMessageInput> stctInput;
00138     DataObjectLockFree<unsigned int> jointNumber;
00139 
00140     // Constructor
00141     YouBotSlaveMsgThreadSafe() {
00142       jointNumber.Set(0);
00143     }
00144 
00145     
00146     // Copy-Constructor
00147     YouBotSlaveMsgThreadSafe(const YouBotSlaveMsgThreadSafe &copy) {
00148       SlaveMessageOutput tempOutput;
00149       SlaveMessageInput tempInput;
00150       unsigned int tempjointNo;
00151       
00152       copy.stctOutput.Get(tempOutput);
00153       stctOutput.Set(tempOutput);
00154       
00155       copy.stctInput.Get(tempInput);
00156       stctInput.Set(tempInput);
00157               
00158       copy.jointNumber.Get(tempjointNo);
00159       jointNumber.Set(tempjointNo);
00160     }
00161 
00162     // Destructor
00163     ~YouBotSlaveMsgThreadSafe() {
00164     }
00165 
00166     // assignment operator
00167     YouBotSlaveMsgThreadSafe & operator=(const YouBotSlaveMsgThreadSafe &copy) {
00168       SlaveMessageOutput tempOutput;
00169       SlaveMessageInput tempInput;
00170       unsigned int tempjointNo;
00171       
00172       copy.stctOutput.Get(tempOutput);
00173       stctOutput.Set(tempOutput);
00174       
00175       copy.stctInput.Get(tempInput);
00176       stctInput.Set(tempInput);
00177               
00178       copy.jointNumber.Get(tempjointNo);
00179       jointNumber.Set(tempjointNo);
00180 
00181       return *this;
00182     }
00183  
00184   };
00185 
00186 } // namespace youbot
00187 
00188 #endif  /* _YOUBOT_SLAVE_MESSAGE_H */
Generated by  doxygen 1.6.3