0
$\begingroup$

I am new in robotics and would like to ask some help.

I am using ESP32 s3 N16r8 for a project with a micro ROS on it for communication. It is only subscribing to a topic.

It's working fine if you first plug the esp32 and execute the script (for running the agent and publishing topic). But if you kill/stop the script, it won't connect to micro ros again, unless you make a hardware reset.

I tried to use the following in code in setup function:

//wait agent comes up
do {
    EXECUTE_EVERY_N_MS(300, state = (RMW_RET_OK == rmw_uros_ping_agent(100, 1)) ? AGENT_AVAILABLE : WAITING_AGENT;);
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    delay(300);

    if (state == AGENT_AVAILABLE)
    break;
} while (1);

Then for the loop function

switch (state) {
case AGENT_AVAILABLE:
  //if setup done, always here. then go to next step
  state = AGENT_CONNECTED;
  break;
case AGENT_CONNECTED:
  EXECUTE_EVERY_N_MS(500, state = (RMW_RET_OK == rmw_uros_ping_agent(30, 1)) ? AGENT_CONNECTED : AGENT_DISCONNECTED;);     
  if (state == AGENT_CONNECTED) {
    audio.setVolume(20);
    rclc_executor_spin_some(&executor, RCL_MS_TO_NS(10));
  }
  break;
case AGENT_DISCONNECTED:
  //if ping doesn't work, then reset board(=wait agent comes up)
  ESP.restart();
  break;
default:
  break;

}

I am not using wifi, only serial communication. Am I missing something? Any help is highly appreciated, thank you!

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.