seed_r7_lower_controller.cpp
Go to the documentation of this file.
2 
3 
5 {
6  ros::param::get("/joint_settings/upper/joints", upper_name_);
7  ros::param::get("/joint_settings/lower/joints", name_);
8  ros::param::get("/joint_settings/lower/aero_index", aero_index_);
9  ros::param::get("/joint_settings/wheel/joints", wheel_name_);
10  ros::param::get("/joint_settings/wheel/aero_index", wheel_aero_index_);
11  int raw_data_size, body_data_size, base_data_size;
12  ros::param::get("/joint_settings/raw_data_size", raw_data_size);
13  ros::param::get("/joint_settings/body_data_size", body_data_size);
14  ros::param::get("/joint_settings/base_data_size", base_data_size);
15 
17  if(lower_->openPort(_port,BAUDRATE)){
18  ROS_INFO("%s is connected", _port.c_str());
19  lower_->flushPort();
20  is_open_ = true;
21  }
22  else{
23  ROS_ERROR("%s is not connected", _port.c_str());
24  is_open_ = false;
25  }
26 
27  raw_data_.resize(raw_data_size);
28  fill(raw_data_.begin(),raw_data_.end(),0);
29 
30  //make table for remap aero <-> ros
31  aero_table_.resize(body_data_size);
32  for(size_t i = 0; i < aero_table_.size() ; ++i){
33  size_t index = std::distance(aero_index_.begin(), std::find(aero_index_.begin(),aero_index_.end(),i));
34  if(index != aero_index_.size()) aero_table_.at(i) = std::make_pair(index,name_.at(index));
35  }
36 
37  wheel_table_.resize(base_data_size);
38  for(size_t i = 0; i < wheel_table_.size() ; ++i){
39  size_t index = std::distance(wheel_aero_index_.begin(), std::find(wheel_aero_index_.begin(),wheel_aero_index_.end(),i));
40  if(index != wheel_aero_index_.size()) wheel_table_.at(i) = std::make_pair(index,wheel_name_.at(index));
41  }
42 }
43 
45 {
47 }
48 
50 {
52 
54 }
55 
56 void robot_hardware::LowerController::sendPosition(uint16_t _time, std::vector<int16_t>& _data)
57 {
58  if(is_open_) raw_data_ = lower_->actuateByPosition(_time, _data.data());
59  else raw_data_.assign(_data.begin(), _data.end());
60 
62 }
63 
65 (std::vector<int16_t>& _ros, std::vector<int16_t>& _aero)
66 {
67  _ros.resize(name_.size());
68  for(size_t i = 0; i < _ros.size(); ++i){
69  if(aero_index_.at(i) != -1) _ros.at(i) = _aero.at(aero_index_.at(i));
70  }
71 }
72 
74 (std::vector<int16_t>& _aero, std::vector<int16_t>& _ros)
75 {
76  _aero.resize(aero_table_.size());
77  for(size_t i = 0; i < _aero.size(); ++i){
78  _aero.at(i) = _ros.at(upper_name_.size() + aero_table_.at(i).first);
79  }
80 }
81 
82 void robot_hardware::LowerController::runScript(uint8_t _number, uint16_t _script)
83 {
84  if(is_open_)lower_->runScript(_number, _script);
85 }
86 void robot_hardware::LowerController::sendVelocity(std::vector<int16_t>& _data)
87 {
88  std::vector<int16_t> send_data(wheel_table_.size());
89  fill(send_data.begin(),send_data.end(),0x7FFF);
90  for(size_t i = 0; i < wheel_table_.size(); ++i){
91  if(wheel_table_.at(i).second != "") send_data.at(i) = _data.at(wheel_table_.at(i).first);
92  }
93 
94  if(is_open_) lower_->actuateBySpeed(send_data.data());
95 }
96 
98 {
99  std::vector<uint16_t> data(30);
100  fill(data.begin(),data.end(),0x7FFF);
101 
102  if(is_open_){
103  for(size_t i=0; i< wheel_aero_index_.size() ; ++i){
104  lower_->onServo(wheel_aero_index_[i] + 1, _value);
105  //reset present position
106  lower_->throughCAN(wheel_aero_index_[i] + 1, 0x6F,0,1,0,0,0);
107  }
108  }
109 }
110 
112 {
113  if(is_open_) return lower_->getTemperatureVoltage(31)[0] * 0.1;
114  else return 0;
115 }
116 
118 {
119  if(is_open_) return lower_->getVersion(0);
120  else return "";
121 }
122 
124 {
125  if(is_open_)lower_->getStatus(_number);
126 
127  //_number == 0xFF : reset flag
128 }
129 
131 {
133  else comm_err_ = false;
134 
135  int16_t status_bit = raw_data_.back();
136  int8_t max_bit_size = 16;
137 
138  if(!is_open_) status_bit = 0;
139  robot_status_.connection_err_ = (status_bit >> error_bit_t::can1_connection)&1 ||
140  (status_bit >> error_bit_t::can2_connection)&1;
141 
142  robot_status_.calib_err_ = (status_bit >> error_bit_t::can1_calibration)&1 ||
143  (status_bit >> error_bit_t::can2_calibration)&1;
144 
145  robot_status_.motor_err_ = (status_bit >> error_bit_t::can1_motor_status)&1 ||
146  (status_bit >> error_bit_t::can2_motor_status)&1;
147 
148  robot_status_.temp_err_ = (status_bit >> error_bit_t::can1_temperature)&1 ||
149  (status_bit >> error_bit_t::can2_temperature)&1;
150 
151  robot_status_.res_err_ = (status_bit >> error_bit_t::can1_response)&1 ||
152  (status_bit >> error_bit_t::can2_response)&1;
153 
154  robot_status_.step_out_err_ = (status_bit >> error_bit_t::can1_step_out)&1 ||
155  (status_bit >> error_bit_t::can2_step_out)&1;
156 
157  robot_status_.p_stopped_err_ = (status_bit >> error_bit_t::can1_protective_stopped)&1 ||
158  (status_bit >> error_bit_t::can2_protective_stopped)&1;
159 
160  robot_status_.power_err_ = (status_bit >> error_bit_t::can1_power)&1 ||
161  (status_bit >> error_bit_t::can2_power)&1;
162 
163 }
std::vector< std::string > wheel_name_
std::vector< std::pair< int, std::string > > aero_table_
std::vector< uint16_t > getStatus(uint8_t _number)
LowerController(const std::string &_port)
std::vector< uint16_t > getTemperatureVoltage(uint8_t _number)
std::vector< int16_t > actuateByPosition(uint16_t _time, int16_t *_data)
void runScript(uint8_t _number, uint16_t _script)
void remapRosToAero(std::vector< int16_t > &_aero, std::vector< int16_t > &_ros)
std::string getVersion(uint8_t _number)
std::vector< int16_t > getPosition(uint8_t _number)
void runScript(uint8_t _number, uint16_t _data)
void throughCAN(uint8_t _send_no, uint8_t _command, uint8_t _data1, uint8_t _data2, uint8_t _data3, uint8_t _data4, uint8_t _data5)
bool openPort(std::string _port, unsigned int _baud_rate)
ROSCPP_DECL bool get(const std::string &key, std::string &s)
#define ROS_INFO(...)
void sendPosition(uint16_t _time, std::vector< int16_t > &_data)
struct robot_hardware::LowerController::RobotStatus robot_status_
void remapAeroToRos(std::vector< int16_t > &_ros, std::vector< int16_t > &_aero)
void sendVelocity(std::vector< int16_t > &_data)
#define ROS_ERROR(...)
std::vector< std::pair< int, std::string > > wheel_table_
aero::controller::AeroCommand * lower_
std::vector< int16_t > actuateBySpeed(int16_t *_data)
void onServo(uint8_t _number, uint16_t _data)
std::vector< std::string > upper_name_


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