Turn on Point kann jetzt schon im Admin aufgerufen werden um den Rover in eine Richtug zu drehen
This commit is contained in:
@@ -227,6 +227,7 @@ def _connect_imu_ros():
|
||||
global IMU_ROS_CLIENT, IMU_ROS_TOPICS
|
||||
|
||||
import roslibpy
|
||||
import imu_rotate
|
||||
|
||||
client = roslibpy.Ros(host=ROSBRIDGE_HOST, port=ROSBRIDGE_PORT)
|
||||
client.run()
|
||||
@@ -239,13 +240,29 @@ def _connect_imu_ros():
|
||||
imu_topic = roslibpy.Topic(client, '/imu/data', 'sensor_msgs/Imu')
|
||||
mag_topic = roslibpy.Topic(client, '/imu/mag', 'sensor_msgs/MagneticField')
|
||||
status_topic = roslibpy.Topic(client, '/imu/status', 'std_msgs/String')
|
||||
rover_cmd_topic = roslibpy.Topic(client, '/rover_command', 'exomy/RoverCommand')
|
||||
imu_topic.subscribe(_on_imu_data_message)
|
||||
mag_topic.subscribe(_on_imu_mag_message)
|
||||
status_topic.subscribe(_on_imu_status_message)
|
||||
rover_cmd_topic.advertise()
|
||||
IMU_ROS_CLIENT = client
|
||||
IMU_ROS_TOPICS = [imu_topic, mag_topic, status_topic]
|
||||
IMU_ROS_TOPICS = [imu_topic, mag_topic, status_topic, rover_cmd_topic]
|
||||
_imu_ros_cache_update(status='ROS verbunden', error='')
|
||||
|
||||
def _publish_rover_cmd(locomotion_mode, vel, steering):
|
||||
try:
|
||||
rover_cmd_topic.publish(roslibpy.Message({
|
||||
'connected': True,
|
||||
'motors_enabled': True,
|
||||
'locomotion_mode': int(locomotion_mode),
|
||||
'vel': int(vel),
|
||||
'steering': int(steering),
|
||||
}))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
imu_rotate.set_publish_fn(_publish_rover_cmd)
|
||||
|
||||
|
||||
def _imu_ros_worker():
|
||||
global IMU_ROS_CLIENT, IMU_ROS_TOPICS
|
||||
@@ -1957,6 +1974,10 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self):
|
||||
if self.path == '/api/imu/rotate-status':
|
||||
import imu_rotate
|
||||
self.write_json(200, {'rotate': imu_rotate.get_rotate_status()})
|
||||
return
|
||||
if self.path == '/api/delay':
|
||||
self.write_json(200, {'delay_seconds': get_delay()})
|
||||
return
|
||||
@@ -1999,7 +2020,8 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
def do_POST(self):
|
||||
raw_body = b'{}'
|
||||
if self.path in ('/api/routes/save', '/api/routes/delete', '/api/imu/heading-offset'):
|
||||
if self.path in ('/api/routes/save', '/api/routes/delete', '/api/imu/heading-offset',
|
||||
'/api/imu/rotate-to'):
|
||||
try:
|
||||
content_length = int(self.headers.get('Content-Length', '0'))
|
||||
except ValueError:
|
||||
@@ -2290,6 +2312,39 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
self.write_json(status_code, response)
|
||||
return
|
||||
|
||||
if self.path == '/api/imu/rotate-to':
|
||||
try:
|
||||
payload = json.loads(raw_body.decode('utf-8'))
|
||||
target_deg = float(payload.get('target_deg', 0))
|
||||
except (UnicodeDecodeError, json.JSONDecodeError, TypeError, ValueError):
|
||||
self.write_json(400, {'status': 'Ungültige Anfrage'})
|
||||
return
|
||||
with IMU_ROS_LOCK:
|
||||
heading = IMU_ROS_CACHE.get('heading_deg')
|
||||
if heading is None:
|
||||
self.write_json(409, {'status': 'Noch keine frischen IMU-Daten'})
|
||||
return
|
||||
import imu_rotate
|
||||
heading_offset = read_imu_heading_calibration()['offset_deg']
|
||||
|
||||
def _get_corrected_heading():
|
||||
with IMU_ROS_LOCK:
|
||||
raw = IMU_ROS_CACHE.get('heading_deg')
|
||||
return get_corrected_heading_deg(raw, heading_offset) if raw is not None else None
|
||||
|
||||
status = imu_rotate.start_rotate(
|
||||
target_deg=target_deg,
|
||||
get_heading_fn=_get_corrected_heading,
|
||||
)
|
||||
self.write_json(200, {'status': 'Drehung gestartet', 'rotate': status})
|
||||
return
|
||||
|
||||
if self.path == '/api/imu/rotate-stop':
|
||||
import imu_rotate
|
||||
imu_rotate.stop_rotate()
|
||||
self.write_json(200, {'status': 'Drehung gestoppt', 'rotate': imu_rotate.get_rotate_status()})
|
||||
return
|
||||
|
||||
actions = {
|
||||
'/api/cold-start-gps': {
|
||||
'handler': cold_start_gps_receiver,
|
||||
|
||||
Reference in New Issue
Block a user