KaCanOpen
 All Classes Functions Variables Typedefs Enumerations Pages
profiles.cpp
1 /*
2  * Copyright (c) 2016, Thomas Keh
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "profiles.h"
33 #include "logger.h"
34 
35 namespace kaco {
36 
37  const std::map<uint16_t,std::map<std::string, const Profiles::Operation>> Profiles::operations {
38  {
39  (uint16_t) 402,
40  {
41  {
42  "enable_operation",
43  [](Device& device,const Value&) -> Value {
44  device.set_entry("controlword", (uint16_t) 0x0006); // shutdown
45  device.set_entry("controlword", (uint16_t) 0x0007); // switch on
46  device.set_entry("controlword", (uint16_t) 0x000F); // enable operation
47  return Value(); // invalid value (return value not needed)
48  }
49  },
50  {
51  "set_controlword_flag",
52  [](Device& device,const Value& flag_name) -> Value {
53  DEBUG_LOG("Set controlword flag "<<flag_name);
54  const uint16_t cw = device.get_entry("controlword");
55  const uint16_t flag = device.get_constant(flag_name);
56  device.set_entry("controlword", static_cast<uint16_t>(cw | flag));
57  return Value();
58  }
59  },
60  {
61  "unset_controlword_flag",
62  [](Device& device,const Value& flag_name) -> Value {
63  DEBUG_LOG("Unset controlword flag "<<flag_name);
64  const uint16_t cw = device.get_entry("controlword");
65  const uint16_t flag = device.get_constant(flag_name);
66  device.set_entry("controlword", static_cast<uint16_t>(cw & ~flag));
67  return Value();
68  }
69  },
70  {
71  "set_target_position",
72  [](Device& device,const Value& target_position) -> Value {
73  DEBUG_LOG("Set target pos to "<<target_position);
74  device.set_entry("Target position", target_position);
75  device.execute("set_controlword_flag","controlword_pp_new_set_point");
76  device.execute("unset_controlword_flag","controlword_pp_new_set_point");
77  return Value();
78  }
79  }
80  }
81  }
82  };
83 
84  const std::map<uint16_t,std::map<std::string, const Value>> Profiles::constants {
85  {
86  (uint16_t) 402,
87  {
88  // profiles
89  { "profile_position_mode", static_cast<int8_t>(1) },
90  { "velocity_mode", static_cast<int8_t>(2) },
91  { "profile_velocity_mode", static_cast<int8_t>(3) },
92  { "torque_profile_mode", static_cast<int8_t>(4) },
93  { "homing_mode", static_cast<int8_t>(6) },
94  { "interpolated_position_mode", static_cast<int8_t>(7) },
95 
96  // control word flags general
97  { "controlword_switch_on", static_cast<uint16_t>(1<<0) },
98  { "controlword_enable_voltage", static_cast<uint16_t>(1<<1) },
99  { "controlword_quick_stop", static_cast<uint16_t>(1<<2) },
100  { "controlword_enable_operation", static_cast<uint16_t>(1<<3) },
101  { "controlword_fault_reset", static_cast<uint16_t>(1<<7) },
102  { "controlword_halt", static_cast<uint16_t>(1<<8) },
103 
104  // control word flags manufacturer specific
105  { "controlword_manufacturer_11", static_cast<uint16_t>(1<<11) },
106  { "controlword_manufacturer_12", static_cast<uint16_t>(1<<12) },
107  { "controlword_manufacturer_13", static_cast<uint16_t>(1<<13) },
108  { "controlword_manufacturer_14", static_cast<uint16_t>(1<<14) },
109  { "controlword_manufacturer_15", static_cast<uint16_t>(1<<15) },
110 
111  // control word flags velocity mode specific
112  { "controlword_vl_rfg_enable", static_cast<uint16_t>(1<<4) },
113  { "controlword_vl_rfg_unlock", static_cast<uint16_t>(1<<5) },
114  { "controlword_vl_use_ref", static_cast<uint16_t>(1<<6) },
115 
116  // control word flags profile position mode specific
117  { "controlword_pp_new_set_point", static_cast<uint16_t>(1<<4) },
118  { "controlword_pp_change_set_immediately", static_cast<uint16_t>(1<<5) },
119  { "controlword_pp_abs_rel", static_cast<uint16_t>(1<<6) },
120 
121  // control word flags homing mode specific
122  { "controlword_hm_operation_start", static_cast<uint16_t>(1<<4) },
123 
124  // control word flags interpolated position mode specific
125  { "controlword_ip_enable_ip_mode", static_cast<uint16_t>(1<<4) },
126 
127  // status word flags general
128  { "statusword_ready_to_switch_on", static_cast<uint16_t>(1<<0) },
129  { "statusword_switched_on", static_cast<uint16_t>(1<<1) },
130  { "statusword_operation_enabled", static_cast<uint16_t>(1<<2) },
131  { "statusword_fault", static_cast<uint16_t>(1<<3) },
132  { "statusword_voltage_enabled", static_cast<uint16_t>(1<<4) },
133  { "statusword_quick_stop", static_cast<uint16_t>(1<<5) },
134  { "statusword_switch_on_disabled", static_cast<uint16_t>(1<<6) },
135  { "statusword_warning", static_cast<uint16_t>(1<<7) },
136  { "statusword_remote", static_cast<uint16_t>(1<<9) },
137  { "statusword_target_reached", static_cast<uint16_t>(1<<10) },
138  { "statusword_internal_limit_active", static_cast<uint16_t>(1<<11) },
139 
140  // status word flags manufacturer specific
141  { "statusword_manufacturer_8", static_cast<uint16_t>(1<<8) },
142  { "statusword_manufacturer_14", static_cast<uint16_t>(1<<14) },
143  { "statusword_manufacturer_15", static_cast<uint16_t>(1<<15) },
144 
145  // status word flags profile position mode specific
146  { "statusword_pp_set_point_acknowledge", static_cast<uint16_t>(1<<12) },
147  { "statusword_pp_following_error", static_cast<uint16_t>(1<<13) },
148 
149  // status word flags profile velocity mode specific
150  { "statusword_pv_speed", static_cast<uint16_t>(1<<12) },
151  { "statusword_pv_max_slippage_error", static_cast<uint16_t>(1<<13) },
152 
153  // status word flags homing mode specific
154  { "statusword_hm_homing_attained", static_cast<uint16_t>(1<<12) },
155  { "statusword_hm_homing_error", static_cast<uint16_t>(1<<13) },
156 
157  // status word flags interpolated position mode specific
158  { "statusword_ip_ip_mode_active", static_cast<uint16_t>(1<<12) }
159  }
160  }
161  };
162 
163 } // end namespace kaco
static const std::map< uint16_t, std::map< std::string, const Operation > > operations
Convenience operations for CiA profiles. Type: map < profile number , map < operation name ...
Definition: profiles.h:56
static const std::map< uint16_t, std::map< std::string, const Value > > constants
Constants for CiA profiles. Type: map < profile number , map < operation name , constant value > > ...
Definition: profiles.h:60