add minimal module4 control example
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import rclpy
|
||||
from flask import Flask
|
||||
from geometry_msgs.msg import Twist
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
rclpy.init()
|
||||
node = rclpy.create_node("web_api")
|
||||
publisher = node.create_publisher(Twist, "/RMC2/cmd_vel", 10)
|
||||
|
||||
|
||||
@app.after_request
|
||||
def cors(response):
|
||||
response.headers["Access-Control-Allow-Origin"] = "*"
|
||||
return response
|
||||
|
||||
|
||||
@app.post("/api/forward")
|
||||
def forward():
|
||||
speed = Twist()
|
||||
speed.linear.x = 0.1
|
||||
|
||||
for _ in range(40):
|
||||
publisher.publish(speed)
|
||||
rclpy.spin_once(node, timeout_sec=0.05)
|
||||
|
||||
for _ in range(5):
|
||||
publisher.publish(Twist())
|
||||
rclpy.spin_once(node, timeout_sec=0.05)
|
||||
|
||||
return "ok"
|
||||
|
||||
app.run(host="0.0.0.0", port=8000, threaded=False)
|
||||
Reference in New Issue
Block a user