add minimal module4 control example
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
export default function App() {
|
||||
|
||||
function forward() {
|
||||
fetch("http://localhost:8000/api/forward", {
|
||||
method: "POST"
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="grid min-h-screen place-items-center bg-zinc-950">
|
||||
<button
|
||||
className="border border-zinc-600 bg-zinc-900 px-8 py-4 text-lg text-white hover:bg-zinc-800"
|
||||
onClick={forward}
|
||||
>
|
||||
Вперёд
|
||||
</button>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -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