Topic publishing always
Closed this issue · 4 comments
System information
- **OS Platform and Distribution Linux Ubuntu 18.04
- **Apollo installed from source
- **Apollo version 5.0
I have a module that writes a message to a topic based on input from another topic. I however see that my topic is always broadcasted even when input topic is not received which I dont want. I have used these implementations for reader and writer
`control_cmd_reader_ = node_->CreateReader(
FLAGS_control_command_topic,
[this](const std::shared_ptr& cmd) {
ADEBUG << "Received control data: run control callback.";
std::lock_guardstd::mutex lock(mutex_);
control_cmd_.CopyFrom(*cmd);
});
mymodule_command_writer_ =
node_->CreateWriter(FLAGS_mymod_command_topic);`
I am later on populating an object of type InteliContcommand with values received from control_cmd_reader and writing it as such
mymodule_command_writer_->Write( std::make_shared<InteliContcommand>(inteli_cnt_cmd));
Please let me know how I can configure my reader/writer to write only when there is data coming in from the reader.
There are two methods.
use trigger module
class YourComponent final : public cyber::Component<ControlCommand>
then send message in proc
, when you receive ControlCommand
then cyber will automatically call proc
.
use reader callback
in your reader callback, you can add a function, and send message in the function.
control_cmd_reader_ = node_->CreateReader(
FLAGS_control_command_topic,
[this](const std::shared_ptr& cmd) {
ADEBUG << "Received control data: run control callback.";
std::lock_guardstd::mutex lock(mutex_);
control_cmd_.CopyFrom(*cmd);
callback(control_cmd_) // which you can do something
});
I am in fact using the trigger module like you suggested. proc has the writer publishing the message, but because of this, everytime cyber calls proc, I am publishing message, albeit with zero values.
I am not very clear on using reader callback. Can you please explain more on callback you have mentioned in the code? You man I should call proc? I guess not, but I am not clear.
I am in fact using the trigger module like you suggested. proc has the writer publishing the message, but because of this, everytime cyber calls proc, I am publishing message, albeit with zero values.
-
Use trigger module is fine. It will call proc when receive
ControlCommand
. It will not when there's no message arrive. So, I don't know what you mean byzero values
, if you sendControlCommand
it will call proc, if you not it will not call. -
It does not care whether the value in the message you send is empty, and sending an empty controlcommand itself is abnormal
-
You do need to check the module is
class YourComponent final : public cyber::Component<ControlCommand>
but not
class ControlComponent final : public apollo::cyber::TimerComponent
Closed due to inactivity. If the problem persists, pls feel free to reopen it or create a new one and refer to it.