seed_r7_upper_controller.cpp
Go to the documentation of this file.
2 
3 
5 {
6  ros::param::get("/joint_settings/upper/joints", name_);
7  ros::param::get("/joint_settings/upper/aero_index", aero_index_);
8  int raw_data_size, body_data_size, base_data_size;
9  ros::param::get("/joint_settings/raw_data_size", raw_data_size);
10  ros::param::get("/joint_settings/body_data_size", body_data_size);
11 
13  if(upper_->openPort(_port,BAUDRATE)){
14  ROS_INFO("%s is connected", _port.c_str());
15  upper_->flushPort();
16  is_open_ = true;
17  }
18  else{
19  ROS_ERROR("%s is not connected", _port.c_str());
20  is_open_ = false;
21  }
22 
23  raw_data_.resize(raw_data_size);
24  fill(raw_data_.begin(),raw_data_.end(),0);
25 
26  //make table for remap aero <-> ros
27  aero_table_.resize(body_data_size);
28  for(size_t i = 0; i < aero_table_.size() ; ++i){
29  size_t index = std::distance(aero_index_.begin(), std::find(aero_index_.begin(),aero_index_.end(),i));
30  if(index != aero_index_.size()) aero_table_.at(i) = std::make_pair(index,name_.at(index));
31  }
32 }
33 
35 {
36  if(is_open_) upper_->closePort();
37 }
38 
40 {
42 
44 }
45 
46 void robot_hardware::UpperController::sendPosition(uint16_t _time, std::vector<int16_t>& _data)
47 {
48  if(is_open_) raw_data_ = upper_->actuateByPosition(_time, _data.data());
49  else raw_data_.assign(_data.begin(), _data.end());
50 
52 }
53 
55 (std::vector<int16_t>& _ros, std::vector<int16_t>& _aero)
56 {
57  _ros.resize(name_.size());
58  for(size_t i = 0; i < _ros.size(); ++i){
59  if(aero_index_.at(i) != -1) _ros.at(i) = _aero.at(aero_index_.at(i));
60  }
61 }
62 
63 
65 (std::vector<int16_t>& _aero, std::vector<int16_t>& _ros)
66 {
67  _aero.resize(aero_table_.size());
68  for(size_t i = 0; i < _aero.size(); ++i){
69  _aero.at(i) = _ros.at(aero_table_.at(i).first);
70  }
71 }
72 
73 void robot_hardware::UpperController::setCurrent(uint8_t _number, uint8_t _max, uint8_t _down)
74 {
75  if(is_open_)upper_->setCurrent(_number, _max, _down);
76 }
77 
78 void robot_hardware::UpperController::runScript(uint8_t _number, uint16_t _script)
79 {
80  if(is_open_)upper_->runScript(_number, _script);
81 }
82 
84 {
85  if(is_open_) return upper_->getVersion(0);
86  else return "";
87 }
88 
90 {
92  else comm_err_ = false;
93 
94  int16_t status_bit = raw_data_.back();
95  int8_t max_bit_size = 16;
96 
97  if(!is_open_) status_bit = 0;
98  robot_status_.connection_err_ = (status_bit >> error_bit_t::can1_connection)&1 ||
99  (status_bit >> error_bit_t::can2_connection)&1;
100 
101  robot_status_.calib_err_ = (status_bit >> error_bit_t::can1_calibration)&1 ||
102  (status_bit >> error_bit_t::can2_calibration)&1;
103 
104  robot_status_.motor_err_ = (status_bit >> error_bit_t::can1_motor_status)&1 ||
105  (status_bit >> error_bit_t::can2_motor_status)&1;
106 
107  robot_status_.temp_err_ = (status_bit >> error_bit_t::can1_temperature)&1 ||
108  (status_bit >> error_bit_t::can2_temperature)&1;
109 
110  robot_status_.res_err_ = (status_bit >> error_bit_t::can1_response)&1 ||
111  (status_bit >> error_bit_t::can2_response)&1;
112 
113  robot_status_.step_out_err_ = (status_bit >> error_bit_t::can1_step_out)&1 ||
114  (status_bit >> error_bit_t::can2_step_out)&1;
115 
116  robot_status_.p_stopped_err_ = (status_bit >> error_bit_t::can1_protective_stopped)&1 ||
117  (status_bit >> error_bit_t::can2_protective_stopped)&1;
118 
119  robot_status_.power_err_ = (status_bit >> error_bit_t::can1_power)&1 ||
120  (status_bit >> error_bit_t::can2_power)&1;
121 }
std::vector< std::pair< int, std::string > > aero_table_
UpperController(const std::string &_port)
std::vector< int16_t > actuateByPosition(uint16_t _time, int16_t *_data)
std::string getVersion(uint8_t _number)
std::vector< int16_t > getPosition(uint8_t _number)
void runScript(uint8_t _number, uint16_t _data)
bool openPort(std::string _port, unsigned int _baud_rate)
ROSCPP_DECL bool get(const std::string &key, std::string &s)
#define ROS_INFO(...)
void setCurrent(uint8_t _number, uint8_t _max, uint8_t _down)
struct robot_hardware::UpperController::RobotStatus robot_status_
aero::controller::AeroCommand * upper_
void setCurrent(uint8_t _number, uint8_t _max, uint8_t _down)
void runScript(uint8_t _number, uint16_t _script)
void remapAeroToRos(std::vector< int16_t > &_ros, std::vector< int16_t > &_aero)
void remapRosToAero(std::vector< int16_t > &_aero, std::vector< int16_t > &_ros)
void sendPosition(uint16_t _time, std::vector< int16_t > &_data)
#define ROS_ERROR(...)


seed_r7_ros_controller
Author(s): Yohei Kakiuchi
autogenerated on Sun Apr 18 2021 02:40:34