Description
When trying to access the arm camera images from an external ROS node, the request fails with an error code. This prevents external applications from using the robot arm’s camera stream.
-
Missing model_id Parameter: The model_id parameter was always None despite being sent from the robot
-
HTTP 400 Bad Request Error: The robot arm was receiving error code 400 when sending requests to the vision API
TM App Version
-
ROS2: Humble
-
TMflow: 2.16
Root Causes Identified
-
Parameter Source Mismatch
The original code only checked for model_id in URL query parameters:
model_id = request.args.get('model_id')
However, Techman robots send parameters via form data in multipart/form-data requests.
-
File Parameter Name Mismatch
The API expected a file parameter named 'file', but Techman robots send images with the parameter name 'image'.
Error Messages
[192.168.10.2] [2025-08-21 16:35:24.136286] -> Post(DET)
model_id: None
model_id is not set
[192.168.10.2] [2025-08-21 16:47:47.092446] -> Post(DET)
Request headers: {'Host': '192.168.10.3:6189', 'Accept': '*/*', 'Content-Length': '1412495', 'Content-Type': 'multipart/form-data; boundary=------------------------83ac530012b1909d', 'Expect': '100-continue'}
Request args: {}
Request form: {'model_id': 'test', 'vision_version': '2.16.3500.0'}
Request files: ['image']
Content-Type: multipart/form-data; boundary=------------------------83ac530012b1909d
model_id: test
No file found in request. Available files: ['image']
Solution
Fix 1: Enhanced model_id parameter retrieval
Modified the post method to check multiple sources for model_id:
# get key/value from multiple sources
model_id = request.args.get('model_id') # from URL query string
if model_id is None:
model_id = request.form.get('model_id') # from form data
if model_id is None and request.is_json:
model_id = request.json.get('model_id') # from JSON body
Fix 2: Support both 'file' and 'image' parameter names
# Check if file exists in request (try both 'file' and 'image' parameter names)
file = None
if 'file' in request.files:
file = request.files['file']
print('Found file parameter: file')
elif 'image' in request.files:
file = request.files['image']
print('Found file parameter: image')
else:
print('No file found in request. Available files: {}'.format(list(request.files.keys())))
result = {
'message': 'fail',
'result': 'file parameter required (tried: file, image)'
}
return jsonify(result)
Fix 3: Added comprehensive error handling and debugging
Added detailed request logging to help diagnose similar issues:
# Debug: print request details
print('Request headers: {}'.format(dict(request.headers)))
print('Request args: {}'.format(dict(request.args)))
print('Request form: {}'.format(dict(request.form)))
print('Request files: {}'.format(list(request.files.keys())))
print('Content-Type: {}'.format(request.content_type))
Testing
After applying the fixes:
- Rebuild the package:
colcon build --packages-select tm_get_status --symlink-install
- Run the service:
ros2 run tm_get_status image_talker
- Test with TechMan robot - should now properly receive
model_id and process images
Description
When trying to access the arm camera images from an external ROS node, the request fails with an error code. This prevents external applications from using the robot arm’s camera stream.
Missing
model_idParameter: Themodel_idparameter was alwaysNonedespite being sent from the robotHTTP 400 Bad Request Error: The robot arm was receiving error code 400 when sending requests to the vision API
TM App Version
ROS2: Humble
TMflow: 2.16
Root Causes Identified
Parameter Source Mismatch
The original code only checked for
model_idin URL query parameters:model_id = request.args.get('model_id')However, Techman robots send parameters via form data in multipart/form-data requests.
File Parameter Name Mismatch
The API expected a file parameter named
'file', but Techman robots send images with the parameter name'image'.Error Messages
Solution
Fix 1: Enhanced model_id parameter retrieval
Modified the
postmethod to check multiple sources formodel_id:Fix 2: Support both 'file' and 'image' parameter names
Fix 3: Added comprehensive error handling and debugging
Added detailed request logging to help diagnose similar issues:
Testing
After applying the fixes:
colcon build --packages-select tm_get_status --symlink-installros2 run tm_get_status image_talkermodel_idand process images