MIRA
CANPowerSupply.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 MetraLabs GmbH (MLAB), GERMANY.
3  * All rights reserved.
4  * Contact: info@MetraLabs.com
5  *
6  * Commercial Usage:
7  * Licensees holding valid commercial licenses may use this file in
8  * accordance with the commercial license agreement provided with the
9  * software or, alternatively, in accordance with the terms contained in
10  * a written agreement between you and MetraLabs.
11  *
12  * GNU General Public License Usage:
13  * Alternatively, this file may be used under the terms of the GNU
14  * General Public License version 3.0 as published by the Free Software
15  * Foundation and appearing in the file LICENSE.GPL3 included in the
16  * packaging of this file. Please review the following information to
17  * ensure the GNU General Public License version 3.0 requirements will be
18  * met: http://www.gnu.org/copyleft/gpl.html.
19  * Alternatively you may (at your option) use any later version of the GNU
20  * General Public License if such license has been publicly approved by
21  * MetraLabs (or its successors, if any).
22  *
23  * IN NO EVENT SHALL "MLAB" BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
24  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
25  * OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLABS" HAS BEEN
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * "MLAB" SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
31  * "AS IS" BASIS, AND "MLAB" HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
32  * SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
33  */
34 
43 #ifndef _MLAB_CANPOWERSUPPLY_H_
44 #define _MLAB_CANPOWERSUPPLY_H_
45 
46 namespace mira { namespace robot {
47 
49 
54 {
55 public:
58 
61  subIndexEnable(0x01),
62  subIndexMaxCurrent(0x03),
63  subIndexCurrent(0x05),
64  subIndexVoltage(0x04),
65  subIndexStatus(0x02),
66  hasVoltage(true)
67  {}
68 
70  virtual ~CANPowerSupply() {}
71 
73  template <typename Reflector>
74  void reflect(Reflector& r)
75  {
76  r.property("MaxCurrent",
77  getter<float>(boost::bind(&CANPowerSupply::getMaxCurrent, this)),
78  setter<float>(boost::bind(&CANPowerSupply::setMaxCurrent, this, _1)),
79  "Max current [A]", serialization::IgnoreMissing());
80 
81  // Enable properties
82  r.property("Enabled",
83  getter<bool>(boost::bind(&CANPowerSupply::isEnabled, this)),
84  setter<bool>(boost::bind(&CANPowerSupply::enable, this, _1)),
85  "Is power enabled", serialization::IgnoreMissing());
86 
87  // Current properties
88  r.roproperty("Current",
89  getter<float>(boost::bind(&CANPowerSupply::getCurrent, this)),
90  "Current current [A]");
91 
92  // only if supply supports voltage information
93  if (hasVoltage)
94  {
95  // Voltage properties
96  r.roproperty("Voltage",
97  getter<float>(boost::bind(&CANPowerSupply::getVoltage, this)),
98  "Current voltage [V]");
99  }
100 
101  // Status properties
102  r.roproperty("Status",
103  getter<std::string>(boost::bind(&CANPowerSupply::getStatus, this)),
104  "Current status");
105  }
106 
108 
109 public:
112 
116  void setMaxCurrent(float current)
117  {
118  uint16 maxCurrent = (uint16)(current*1000.0f);
119  sdoClient->writeSync<uint16>(nodeID, index, subIndexMaxCurrent, maxCurrent);
120  }
121 
126  {
127  return 0.001f * sdoClient->readSync<uint16>(nodeID, index, subIndexMaxCurrent);
128  }
129 
133  void enable(bool enable)
134  {
135  sdoClient->writeSync<uint8>(nodeID, index, subIndexEnable, enable ? 0x01 : 0x00);
136  }
137 
141  bool isEnabled()
142  {
143  return sdoClient->readSync<uint8>(nodeID, index, subIndexEnable) > 0x00;
144  }
145 
149  float getCurrent()
150  {
151  return 0.001f * sdoClient->readSync<uint16>(nodeID, index, subIndexCurrent);
152  }
153 
157  float getVoltage()
158  {
159  return 0.001f * sdoClient->readSync<uint16>(nodeID, index, subIndexVoltage);
160  }
161 
165  virtual std::string getStatus()
166  {
167  uint8 status = sdoClient->readSync<uint8>(nodeID, index, subIndexStatus);
168  std::string r = (status & 0x01) ? "on" : "off";
169  if ((status & 0x01) && (status & 0x02))
170  r += ", error";
171  return r;
172  }
173 
175 
176 public:
178  uint8 nodeID;
179 
181  uint16 index;
182 
185 
188 
191 
194 
197 
200 
203 };
204 
206 
207 }}
208 
209 #endif
mira::can::CANOpenSDOClientPtr sdoClient
Definition: CANPowerSupply.h:199
void enable(bool enable)
Enable the power supply.
Definition: CANPowerSupply.h:133
uint8 subIndexCurrent
Subindex for retrieving the current.
Definition: CANPowerSupply.h:190
uint8 subIndexMaxCurrent
Subindex for setting/retrieving max current.
Definition: CANPowerSupply.h:187
uint8 subIndexStatus
Subindex for retrieving the status.
Definition: CANPowerSupply.h:196
uint16 index
Index.
Definition: CANPowerSupply.h:181
bool hasVoltage
Does this supply support reading voltage information.
Definition: CANPowerSupply.h:202
CANPowerSupply()
Constructor.
Definition: CANPowerSupply.h:60
boost::shared_ptr< CANOpenSDOClient > CANOpenSDOClientPtr
uint8 nodeID
Id of the can node.
Definition: CANPowerSupply.h:178
float getVoltage()
Return the current voltage.
Definition: CANPowerSupply.h:157
uint8 subIndexVoltage
Subindex for retrieving the voltage.
Definition: CANPowerSupply.h:193
uint8 subIndexEnable
Subindex for enabling the power supply.
Definition: CANPowerSupply.h:184
void reflect(Reflector &r)
Reflect for serialization.
Definition: CANPowerSupply.h:74
Base class for SCITOS modules that act as power supply.
Definition: CANPowerSupply.h:53
float getMaxCurrent()
Return the maximum value for current.
Definition: CANPowerSupply.h:125
void setMaxCurrent(float current)
Set the maximum current.
Definition: CANPowerSupply.h:116
virtual ~CANPowerSupply()
Destructor.
Definition: CANPowerSupply.h:70
float getCurrent()
Return the current current.
Definition: CANPowerSupply.h:149
bool isEnabled()
Is the power supply enabled.
Definition: CANPowerSupply.h:141
virtual std::string getStatus()
Return the status [(on,off)|error] of the power supply.
Definition: CANPowerSupply.h:165