Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add switchbot status publisher #505

Merged
merged 9 commits into from
Jul 10, 2024

Conversation

y-yosuke
Copy link
Contributor

  • add codes for publishing SwitchBot device statuses
  • mod switchbot_ros_client.py with adding wait_for_server() after creating the action client for stability

@@ -17,6 +17,8 @@ def __init__(self,
actionname,
SwitchBotCommandAction
)
rospy.loginfo("Waiting for action server to start.")
self.action_client.wait_for_server()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically it is nice to check if action server is active.
But there are some cases that user want to launch this type of client before action server is launched.
And currently this client assumes that initialization of client class has finished even action server is inactive and we want to preserve default behavior of our code so that our robot demonstration works without changing code.

So could you add timeout args to __init__ and set some limited default to it (e.g. '5' or so on) and use it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed timeout in wait_for_server() as an additional __init()__ argment with 5 [sec] default value.

    def __init__(self,
                 actionname='switchbot_ros/switch',
                 topicname='switchbot_ros/devices',
                 timeout=5):
        rospy.loginfo("Waiting for action server to start. (timeout: " + str(timeout) + "[sec])")
        self.action_client.wait_for_server(timeout=rospy.Duration(timeout,0))


float64 battery # the current battery level, 0-100

string power # ON/OFF state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about bool instead of string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the type to bool.

float64 battery # the current battery level, 0-100

string power # ON/OFF state
string device_mode # pressMode, switchMode, or customizeMode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add candidates constants of this field to this message like https://docs.ros.org/en/noetic/api/visualization_msgs/html/msg/Marker.html ?

string DEVICEMODE_PRESS = "pressMode"

or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added 3 candedate constants as

string DEVICEMODE_PRESS     = "pressMode"
string DEVICEMODE_SWITCH    = "switchMode"
string DEVICEMODE_CUSTOMIZE = "customizeMode"

@@ -0,0 +1,6 @@
Header header # timestamp

string power # ON/OFF state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool suggestion like above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the type to bool.

Header header # timestamp

string power # ON/OFF state
string color # the color value, RGB "255:255:255"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about split this field into color_r, color_g, color_b integers instead of string so that we can easily set value to here. There are some languages that do not support rich string manipulation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split color int color_r, color_g and color_b.

                        rgb_string       = status['color']
                        r, g, b = map(int, rgb_string.split(':'))
                        msg.color_r      = r
                        msg.color_g      = g
                        msg.color_b      = b

Copy link
Contributor

@sktometometo sktometometo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your contribution!.

@y-yosuke
Copy link
Contributor Author

Thanks for your review.

@k-okada k-okada merged commit fb32bec into jsk-ros-pkg:master Jul 10, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants