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

funtional self drive #3

Open
goodgodgd opened this issue Nov 4, 2020 · 0 comments
Open

funtional self drive #3

goodgodgd opened this issue Nov 4, 2020 · 0 comments

Comments

@goodgodgd
Copy link
Owner

#!/usr/bin/env python
from __future__ import print_function
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan

count = 0
publisher = None


def lds_callback(scan):
    global count
    global publisher
    print("scan[0]:", scan.ranges[0])
    turtle_vel = Twist()
    if count < 100:
        turtle_vel.linear.x = 0.1
        count += 1
    else:
        turtle_vel.linear.x = 0.0
    turtle_vel.angular.z = 0.0
    publisher.publish(turtle_vel)


def main():
    global publisher
    rospy.init_node('self_drive')
    publisher = rospy.Publisher('cmd_vel', Twist, queue_size=1)
    subscriber = rospy.Subscriber('scan', LaserScan, lds_callback)
    rospy.spin()

if __name__ == "__main__":
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant