Skip to content

Instantly share code, notes, and snippets.

@alesolano
Created May 7, 2019 11:38
Show Gist options
  • Save alesolano/fe0ec5eed949e092e4d25d1b53f60c87 to your computer and use it in GitHub Desktop.
Save alesolano/fe0ec5eed949e092e4d25d1b53f60c87 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import rclpy
from rclpy.node import Node
from rclpy.qos import qos_profile_sensor_data
from hrim_actuator_rotaryservo_msgs.msg import GoalRotaryServo
class MinimalPublisher(Node):
def __init__(self):
# Initialize Node with name "mara_minimal_publisher"
super().__init__('mara_minimal_publisher')
# Create a publisher on topic "/hrim_actuation_servomotor_000000000001/goal_axis1"
self.pub_ = self.create_publisher(GoalRotaryServo, '/hrim_actuation_servomotor_000000000001/goal_axis1',
qos_profile=qos_profile_sensor_data)
# Create message with the same type as the topic, GoalRotaryServo
self.msg = GoalRotaryServo()
def publish_once(self):
# Fill message content
position_deg = 30.
self.msg.position = position_deg * 3.1416/180 # Position to rads
self.msg.velocity = 0.4 # Velocity in rads/s
self.msg.control_type = 4 # Position and velocity control
# Publish message!
self.pub_.publish(self.msg)
def main(args=None):
rclpy.init(args=args)
minimal_publisher = MinimalPublisher()
minimal_publisher.publish_once()
minimal_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment