main.cpp (b228cea2faa676f70e84f0b3b4fc9e422cf4f8d9) | main.cpp (232ffe4e03d92e08b8d564b23856155b31492619) |
---|---|
1/** 2 * Copyright 2017 Google Inc. 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 --- 156 unchanged lines hidden (view full) --- 165 timer.expires_after(initialStartTime); 166 } 167 // re-try control loop, set up a delay. 168 else 169 { 170 timer.expires_after(delayTeime); 171 } 172 count++; | 1/** 2 * Copyright 2017 Google Inc. 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 --- 156 unchanged lines hidden (view full) --- 165 timer.expires_after(initialStartTime); 166 } 167 // re-try control loop, set up a delay. 168 else 169 { 170 timer.expires_after(delayTeime); 171 } 172 count++; |
173 timer.async_wait( 174 [](const boost::system::error_code& error) { 175 if (error == boost::asio::error::operation_aborted) 176 { 177 return; 178 } 179 try 180 { 181 restartControlLoops(); 182 // reset count after succesful restartControlLoops() 183 count = 0; 184 } 185 catch (const std::exception& e) 186 { 187 if (count >= 5) 188 { 189 std::cerr 190 << "Failed to restartControlLoops after multiple tries" 191 << std::endl; 192 throw std::runtime_error(e.what()); 193 } | 173 timer.async_wait([](const boost::system::error_code& error) { 174 if (error == boost::asio::error::operation_aborted) 175 { 176 return; 177 } |
194 | 178 |
195 std::cerr << count 196 << " Failed during restartControlLoops, try again: " 197 << e.what() << "\n"; 198 tryRestartControlLoops(false); 199 } 200 }); | 179 // for the last loop, don't elminate the failure of restartControlLoops. 180 if (count >= 5) 181 { 182 restartControlLoops(); 183 // reset count after succesful restartControlLoops() 184 count = 0; 185 return; 186 } |
201 | 187 |
188 // retry when restartControlLoops() has some failure. 189 try 190 { 191 restartControlLoops(); 192 // reset count after succesful restartControlLoops() 193 count = 0; 194 } 195 catch (const std::exception& e) 196 { 197 std::cerr << count 198 << " Failed during restartControlLoops, try again: " 199 << e.what() << "\n"; 200 tryRestartControlLoops(false); 201 } 202 }); 203 |
|
202 return; 203} 204 205} // namespace pid_control 206 207int main(int argc, char* argv[]) 208{ 209 loggingPath = ""; --- 58 unchanged lines hidden --- | 204 return; 205} 206 207} // namespace pid_control 208 209int main(int argc, char* argv[]) 210{ 211 loggingPath = ""; --- 58 unchanged lines hidden --- |