cob_voltage_control_common.cpp
Go to the documentation of this file.
00001 //ROS typedefs
00002 #include "ros/ros.h"
00003 #include <pr2_msgs/PowerBoardState.h>
00004 #include <pr2_msgs/PowerState.h>
00005 #include <cob_relayboard/EmergencyStopState.h>
00006 #include <std_msgs/Float64.h>
00007 
00008 //#include <libphidgets/phidget21.h>
00009 
00010 
00011 class cob_voltage_control_config
00012 {
00013 public:
00014     double min_voltage;
00015     double max_voltage;
00016     double max_voltage_res;
00017     int num_voltage_port;
00018     int num_em_stop_port;
00019     int num_scanner_em_port;
00020 };
00021 
00022 class cob_voltage_control_data
00023 {
00024 // autogenerated: don't touch this class
00025 public:
00026     //configuration data
00027 
00028     //input data
00029     int in_phidget_voltage;
00030     int in_phidget_current;
00031 
00032     //output data
00033     pr2_msgs::PowerBoardState out_pub_em_stop_state_;
00034     pr2_msgs::PowerState out_pub_powerstate_;
00035     cob_relayboard::EmergencyStopState out_pub_relayboard_state;
00036     std_msgs::Float64 out_pub_voltage;
00037     std_msgs::Float64 out_pub_current;
00038 };
00039 
00040 //document how this class has to look
00041 //never change after first generation
00042 class cob_voltage_control_impl
00043 {
00044 
00045 public:
00046 
00047     //CPhidgetInterfaceKitHandle IFK;
00048     cob_voltage_control_impl()
00049     {
00050         //user specific code
00051     }
00052     void configure() 
00053     {
00054     }
00055     void update(cob_voltage_control_data &data, cob_voltage_control_config config)
00056     {
00057         //user specific code
00058         //Get Battery Voltage
00059         int voltageState = -1;
00060         //Get Battery Current
00061         int currentState = -1;
00062 //      CPhidgetInterfaceKit_getSensorValue((CPhidgetInterfaceKitHandle)IFK, config.num_voltage_port, &voltageState);
00063         voltageState = data.in_phidget_voltage;
00064         currentState = data.in_phidget_current;
00065 
00066         ROS_DEBUG("Sensor: %d", voltageState);
00067         ROS_DEBUG("Sensor: %d", currentState);
00068 
00069         //Calculation of real voltage 
00070         //max_voltage = 70V ; max_counts = 999
00071         double max_counts = 725.0; // 3v => max
00072         double voltage = voltageState * config.max_voltage_res/max_counts;
00073         data.out_pub_voltage.data = voltage;
00074         ROS_DEBUG("Current voltage %f", voltage);
00075 
00076         data.out_pub_current.data = currentState;
00077         ROS_DEBUG("Current Strom %f", voltage);
00078 
00079         //Linear calculation for percentage
00080         double percentage =  (voltage - config.min_voltage) * 100/(config.max_voltage - config.min_voltage);
00081 
00082         data.out_pub_powerstate_.header.stamp = ros::Time::now();
00083         data.out_pub_powerstate_.power_consumption = 0.0;
00084         data.out_pub_powerstate_.time_remaining = ros::Duration(1000);
00085         data.out_pub_powerstate_.relative_capacity = percentage;
00086 
00087         data.out_pub_em_stop_state_.header.stamp = ros::Time::now();
00088         data.out_pub_em_stop_state_.run_stop = false;
00089         data.out_pub_em_stop_state_.wireless_stop = false;
00090 
00091     }
00092     
00093     void exit()
00094     {
00095     }
00096 
00097 };


cob_voltage_control
Author(s): Alexander Bubeck
autogenerated on Thu Aug 27 2015 12:45:45