@@ -15,7 +15,8 @@ PacificSpiritCapacitorDriver::PacificSpiritCapacitorDriver()
1515 : super_capacitor::SuperCapacitorBase(){}
1616
1717void PacificSpiritCapacitorDriver::init (std::string can_interface){
18- can_filters_.push_back ({.can_id = 0x2c8 , .can_mask = CAN_EFF_MASK});
18+ can_filters_.push_back ({.can_id = 0x2c7 , .can_mask = CAN_EFF_MASK});
19+ can_filters_.push_back ({.can_id = 0x2c6 , .can_mask = CAN_EFF_MASK});
1920 // Initialize CAN driver
2021 can_driver_ = std::make_unique<meta_hardware::CanDriver>(can_interface, false , can_filters_);
2122
@@ -37,7 +38,11 @@ std::unordered_map<std::string, double> PacificSpiritCapacitorDriver::get_state(
3738 {" max_discharge_power" , max_discharge_power_},
3839 {" base_power" , base_power_},
3940 {" cap_energy_percentage" , cap_energy_percentage_},
40- {" cap_state" , cap_state_}
41+ {" cap_state" , cap_state_},
42+ {" input_voltage" , input_voltage_},
43+ {" capacitor_voltage" , capacitor_voltage_},
44+ {" input_current" , input_current_},
45+ {" target_power" , target_power_fb_}
4146 };
4247}
4348
@@ -49,15 +54,26 @@ void PacificSpiritCapacitorDriver::rx_loop(std::stop_token stop_token) {
4954 while (!stop_token.stop_requested ()) {
5055 try {
5156 can_frame can_msg = can_driver_->read (2000 );
52-
53- max_discharge_power_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [0 ]) |
54- (static_cast <uint16_t >(can_msg.data [1 ]) << 8 )) / 100.0 );
55- base_power_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [2 ]) |
56- (static_cast <uint16_t >(can_msg.data [3 ]) << 8 )) / 100.0 );
57- cap_energy_percentage_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [4 ]) |
58- (static_cast <uint16_t >(can_msg.data [5 ]) << 8 )) / 100.0 );
59- cap_state_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [6 ]) |
60- (static_cast <uint16_t >(can_msg.data [7 ]) << 8 )) / 100.0 );
57+ if (can_msg.can_id == 0x2c7 ){
58+ max_discharge_power_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [0 ]) |
59+ (static_cast <uint16_t >(can_msg.data [1 ]) << 8 ))) / 100.0 ;
60+ base_power_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [2 ]) |
61+ (static_cast <uint16_t >(can_msg.data [3 ]) << 8 ))) / 100.0 ;
62+ cap_energy_percentage_ = static_cast <double >(static_cast <int16_t >(static_cast <int16_t >(can_msg.data [4 ]) |
63+ (static_cast <int16_t >(can_msg.data [5 ]) << 8 )));
64+ cap_state_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [6 ]) |
65+ (static_cast <uint16_t >(can_msg.data [7 ]) << 8 )));
66+ }else if (can_msg.can_id == 0x2c6 ){
67+ input_voltage_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [0 ]) |
68+ (static_cast <uint16_t >(can_msg.data [1 ]) << 8 ))) / 100.0 ;
69+ capacitor_voltage_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [2 ]) |
70+ (static_cast <uint16_t >(can_msg.data [3 ]) << 8 ))) / 100.0 ;
71+ input_current_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [4 ]) |
72+ (static_cast <uint16_t >(can_msg.data [5 ]) << 8 ))) / 100.0 ;
73+ target_power_fb_ = static_cast <double >(static_cast <uint16_t >(static_cast <uint16_t >(can_msg.data [6 ]) |
74+ (static_cast <uint16_t >(can_msg.data [7 ]) << 8 ))) / 100.0 ;
75+ }
76+
6177 } catch (const meta_hardware::CanIOException &e) {
6278 std::cerr << " Error reading super capacitor CAN message: " << e.what () << std::endl;
6379 }
@@ -66,7 +82,7 @@ void PacificSpiritCapacitorDriver::rx_loop(std::stop_token stop_token) {
6682}
6783
6884void PacificSpiritCapacitorDriver::tx (){
69- can_frame tx_frame{.can_id = 0x2c7 , .len = 8 , .data = {0 }};
85+ can_frame tx_frame{.can_id = 0x2c8 , .len = 8 , .data = {0 }};
7086 tx_frame.data [0 ] = static_cast <uint8_t >(static_cast <uint32_t >(target_power_ * 100.0 ) & 0xFF );
7187 tx_frame.data [1 ] = static_cast <uint8_t >(static_cast <uint32_t >(target_power_ * 100.0 ) >> 8 );
7288 tx_frame.data [2 ] = static_cast <uint8_t >(static_cast <uint32_t >(referee_power_ * 100.0 ) & 0xFF );
0 commit comments