Flashing process working ok. Need to add a method to allow specific params to be written, passed to the program as a cmd line arg
Create and publish a Docker image / build-and-push-image (push) Has been cancelled Details

This commit is contained in:
Emran Billah 2024-06-25 18:14:32 -03:00
parent b0581882d3
commit e2b7b95db3
4 changed files with 60 additions and 58 deletions

View File

@ -0,0 +1,21 @@
version: "3.8"
services:
xbee-mav:
command: rosrun xbee_ros_node xbee_config /dev/ttyUSB0 230400
build:
context: .
dockerfile: Dockerfile
devices:
- /dev/ttyUSB0:/dev/ttyUSB0
environment:
- "ROS_MASTER_URI=http://ros-master:11311"
networks:
- sim_network
networks:
sim_network:
driver: bridge

View File

@ -26,9 +26,7 @@ services:
- sim_network - sim_network
xbee-mav: xbee-mav:
command: tail -f /dev/null command: rosrun xbee_ros_node xbee_config /dev/ttyUSB0 230400
# command: roslaunch xbee_ros_node xbeemav.launch baud:=230400 port:="/dev/ttyUSB0" drone:="master" mode:="swarm"
container_name: xbee-mav
depends_on: depends_on:
- ros-master - ros-master
build: build:

View File

@ -13,58 +13,41 @@ bool setupXBee(const std::string &device_port, const unsigned int baud_rate) {
XBeeModule xbee_module; XBeeModule xbee_module;
XMLConfigParser config_parser; XMLConfigParser config_parser;
if (xbee_module.Init_Port(device_port, baud_rate)) { // Init port at specified baud rate
if (!xbee_module.Init_Port(device_port, baud_rate)) {
std::cout << "XBee Configuration Failed. Could not Init_Port." << std::endl;
return false;
}
// Run xbee flashing process in a separate thread
std::thread th_service(&XBeeModule::Run_Service, &xbee_module); std::thread th_service(&XBeeModule::Run_Service, &xbee_module);
while (!xbee_module.Is_Connected() && // Wait till connection to device is established
!xbee_module.Check_Time_Out_Exceeded()) { while (!xbee_module.Is_Connected() && !xbee_module.Check_Time_Out_Exceeded()) {
continue; continue;
} }
if (xbee_module.Is_Connected()) { // Load external config file
std::cout << "Connected to XBee." << std::endl; if (!config_parser.Load_Config()) {
std::cout << "Loading Config File..." << std::endl; std::cout << "XBee Configuration Failed. Could not config file." << std::endl;
return false;
}
if (config_parser.Load_Config()) { // Flash config params to device
std::cout << "Config Loaded Successfully." << std::endl; std::cout << "Connected to XBee. Flashing Config File..." << std::endl;
std::cout << "Transferring Data..." << std::endl; std::vector<XBee_Parameter_S> *config_parameters = config_parser.Get_Loaded_Parameters();
std::vector<XBee_Parameter_S> *config_parameters = for (auto& param : *config_parameters) {
config_parser.Get_Loaded_Parameters(); std::string current_command = "";
xbee_module.Format_AT_Command(param, &current_command);
for (std::size_t i = 0; i < config_parameters->size(); i++) {
std::string current_command;
xbee_module.Format_AT_Command(config_parameters->at(i),
&current_command);
xbee_module.Send_Data(current_command); xbee_module.Send_Data(current_command);
} }
std::string write_command = "ATWR \r"; std::string write_command = "ATWR \r";
xbee_module.Send_Data(write_command); xbee_module.Send_Data(write_command);
}
}
// Kill service once device has been flashed
th_service.join(); th_service.join();
std::cout << "Exiting AT Command Mode..." << std::endl;
if (xbee_module.Is_Connected())
{
xbee_module.Exit_AT_Command_Mode(); xbee_module.Exit_AT_Command_Mode();
if (config_parser.Is_Config_Loaded_Successfully()) std::cout << "Flashing process complete." << std::endl;
{
std::cout << "XBee Configured Successfully." << std::endl;
return true; return true;
}
else
{
std::cout << "XBee Configuration Failed." << std::endl;
}
}
else
{
std::cout << "XBee Configuration Failed." << std::endl;
}
}
return false;
} }

View File

@ -13,7 +13,7 @@ int main(int argc, char*argv[])
{ {
std::string device_port; std::string device_port;
unsigned int baud_rate = 0; unsigned int baud_rate = 0;
const unsigned int DEFAULT_BAUD_RATE = 9600; const unsigned int DEFAULT_BAUD_RATE = 230400;
const std::string DEFAULT_DEVICE_PORT = "/dev/ttyUSB0"; const std::string DEFAULT_DEVICE_PORT = "/dev/ttyUSB0";
if (argc < 1) if (argc < 1)
@ -26,7 +26,7 @@ int main(int argc, char*argv[])
else else
sscanf(argv[2], "%u", &baud_rate); sscanf(argv[2], "%u", &baud_rate);
//setupXBee(device_port, baud_rate); setupXBee(device_port, baud_rate);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {