cob_voltage_control_common.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 //ROS typedefs
19 #include "ros/ros.h"
20 #include <cob_msgs/PowerState.h>
21 #include <cob_msgs/EmergencyStopState.h>
22 #include <std_msgs/Float64.h>
23 #include <algorithm>
24 
26 {
27 public:
28  double min_voltage;
29  double max_voltage;
34 };
35 
37 {
38 // autogenerated: don't touch this class
39 public:
40  //configuration data
41 
42  //input data
45 
46  //output data
47  cob_msgs::PowerState out_pub_power_state_;
48  cob_msgs::EmergencyStopState out_pub_em_stop_state_;
49  std_msgs::Float64 out_pub_voltage_;
50  std_msgs::Float64 out_pub_current_;
51 };
52 
53 //document how this class has to look
54 //never change after first generation
56 {
57 
58 public:
59 
60  //CPhidgetInterfaceKitHandle IFK;
62  {
63  //user specific code
64  }
65  void configure()
66  {
67  }
69  {
70  //user specific code
71  //Get Battery Voltage
72  double voltage_raw = 0;
73  voltage_raw = data.in_phidget_voltage;
74  //Get Battery Current
75  double current_raw = 0;
76  current_raw = data.in_phidget_current;
77 
78  ROS_DEBUG("voltage_raw: %f", voltage_raw);
79  ROS_DEBUG("current_raw: %f", current_raw);
80 
81  //Calculation of real voltage
82  //max_voltage = 50V ; max_counts = 999
83  //from measurements: 49.1 V => 486 counts
84  double max_counts = 693.0; // 3v => max
85  double voltage = voltage_raw * config.max_voltage_res/max_counts;
86  data.out_pub_voltage_.data = voltage;
87  ROS_DEBUG("voltage %f", voltage);
88 
89  //current calculation
90  //500 counts => 0 A
91  //999 counts => 2.5 A
92  //000 counts => -2.5 A
93  double count_min = 611;
94  double count_max = 450;
95  double v_min = -3.0;
96  double v_max = 1.6;
97 
98  double current = v_min+(v_max - v_min)*(current_raw-count_min)/(count_max - count_min);
99  data.out_pub_current_.data = current;
100  ROS_DEBUG("current %f", current);
101 
102  bool charging;
103  if (current > 0){charging = true;}
104  else {charging = false;}
105 
106  //Linear calculation for percentage
107  double percentage = (voltage - config.min_voltage) * 100/(config.max_voltage - config.min_voltage);
108  percentage = std::min(percentage, 100.0);
109 
110  data.out_pub_power_state_.header.stamp = ros::Time::now();
111  data.out_pub_power_state_.voltage = voltage;
112  data.out_pub_power_state_.current = current;
113  data.out_pub_power_state_.power_consumption = voltage * current;
114  data.out_pub_power_state_.relative_remaining_capacity = percentage;
115  data.out_pub_power_state_.charging = charging;
116 
117  }
118 
119  void exit()
120  {
121  }
122 
123 };
cob_msgs::PowerState out_pub_power_state_
cob_msgs::EmergencyStopState out_pub_em_stop_state_
static Time now()
void update(cob_voltage_control_data &data, cob_voltage_control_config config)
#define ROS_DEBUG(...)


cob_voltage_control
Author(s): Alexander Bubeck
autogenerated on Wed Apr 7 2021 02:11:57