XiaomiRobotVacuumProtocol icon indicating copy to clipboard operation
XiaomiRobotVacuumProtocol copied to clipboard

Persistent maps, virtual walls, and forbidden zones

Open JohnRev opened this issue 6 years ago • 20 comments

Hello,

I came upon the following commands on a gen2 vacuum with v001780 firmware:

set_lab_status
start_edit_map
end_edit_map
save_map
reset_map
use_new_map
use_old_map
get_persist_map_v1

mirobo raw-command set_lab_status 1 allows the robot to "remember" maps after a reboot. The start_edit_map, end_edit_map, and save_map appear to be related to the virtual walls and forbidden zones functionality. I believe a JSON is expected as parameters for the function. I do not have the xiaomi app, and I was not able to figure out the format of these parameters.

Note that calling start_edit_map, end_edit_map, or save_map without first enabling the lab_status will result in the following response: The Lab Status is disable.

Not sure what the use_new_map, use_old_map, and get_persist_map do.

JohnRev avatar Dec 15 '18 09:12 JohnRev

I'm also seeing:

get_fresh_map_v2
get_fresh_map
get_persist_map_v2
get_persist_map

It is also possible that persistent maps are stored in the mii cloud and downloaded if requested.

cryptomilk avatar Dec 15 '18 17:12 cryptomilk

3.3.9_001633

Lab mode ON:

req: {'from': '4', 'id': ##MESSAGE_ID##, 'method': 'set_lab_status', 'params': [1]} res: {'id': ##MESSAGE_ID##, 'result': ['ok']}

Lab mode OFF:

req: {'from': '4', 'id': ##MESSAGE_ID##, 'method': 'set_lab_status', 'params': [0]} res: {'id': ##MESSAGE_ID##, 'result': ['ok']}

Software barrier:

req: {'from': '4', 'id': 666, 'method': 'save_map', 'params': [[1, 33800, 27850, 34900, 28700]]} res: {'id': ##MESSAGE_ID##, 'result': ['ok']}

No-go zone:

req: {'from': '4', 'id': ##MESSAGE_ID##, 'method': 'save_map', 'params': [[0, 27000, 32000, 30750, 32000, 30750, 30250, 27000, 30250]]} res: {'id': ##MESSAGE_ID##, 'result': ['ok']}

FeatureExpert avatar Dec 16 '18 11:12 FeatureExpert

Thanks for sharing these, @FeatureExpert!! The params of software barrier and no-go zones seem like coordinates? Software barrier takes a vector of [id, x1,y1,x2,y2] And no-go zone takes [id, x1,y1,x2,y2,x3,y3,x4,y4], which are the corners of the zone rectangle? Edit: see @JensBuchta's comment. The first parameter appears to be a type: 0 = zone, 1 = barrier

JohnRev avatar Dec 16 '18 14:12 JohnRev

It looks like these features are yet to be ported to the Gen 1 Firmware. But given the similarities I would hope to see it soon

dugite-code avatar Dec 17 '18 02:12 dugite-code

I'm not sure these numbers. Some kind of coordinates for sure, but I do not know yet how to calculate them correctly. My image with the map is 900x767, so the coordinates does not match the size. But maybe I generate map incorrectly...

FeatureExpert avatar Dec 18 '18 19:12 FeatureExpert

Hi,

This may be a stupid question but how can you get the list of the commands ? I did not find any explanation of the robot API.

Thanks

Youkier avatar Dec 18 '18 22:12 Youkier

@FeatureExpert I guess they would be like the zoned_cleanup coordinate system, where the dock is at (2500,2500) or something like that

JohnRev avatar Dec 18 '18 22:12 JohnRev

You are probably right. So we can set coords as follows counting from bottom left corner and where the dock is at [25500, 25500]:

[id, barrier_start_x, barrier_start_y, barrier_end_x, barrier_end_y]

or

[id, zone_top_left_x, zone_top_left_y, zone_top_right_x, zone_top_right_y, zone_bottom_right_x, zone_bottom_right_y, zone_bottom_left_x, zone_bottom_left_y]

or even barrier and no-go zone in one command:

[[id, barrier_start_x, barrier_start_y, barrier_end_x, barrier_end_y], [id, zone_top_left_x, zone_top_left_y, zone_top_right_x, zone_top_right_y, zone_bottom_right_x, zone_bottom_right_y, zone_bottom_left_x, zone_bottom_left_y]]

FeatureExpert avatar Dec 19 '18 00:12 FeatureExpert

Seems the first argument of the array is not an id, but rather a type: 0 = zone, 1 = barrier. I can create multiple zones with 0, one zone 0, next zone 1 didn't work. Tested with FW 1633.

JensBuchta avatar Dec 20 '18 19:12 JensBuchta

@JensBuchta nice find!

JohnRev avatar Dec 20 '18 21:12 JohnRev

You are probably right. So we can set coords as follows counting from bottom left corner and where the dock is at [25500, 25500]:

[id, barrier_start_x, barrier_start_y, barrier_end_x, barrier_end_y]

or

[id, zone_top_left_x, zone_top_left_y, zone_top_right_x, zone_top_right_y, zone_bottom_right_x, zone_bottom_right_y, zone_bottom_left_x, zone_bottom_left_y]

or even barrier and no-go zone in one command:

[[id, barrier_start_x, barrier_start_y, barrier_end_x, barrier_end_y], [id, zone_top_left_x, zone_top_left_y, zone_top_right_x, zone_top_right_y, zone_bottom_right_x, zone_bottom_right_y, zone_bottom_left_x, zone_bottom_left_y]]

sorry for my stupid question : how are no-go zones and barriers removed or how can i see these zones or barriers ?

usbdem avatar Feb 15 '19 23:02 usbdem

Calling get_persistent_map_v1 triggers a map upload. However I'm not sure what the param does. With the new Valetudo which supports map uploading, I've added a log message and it uploads a map each time I call it.

cryptomilk avatar Apr 07 '19 08:04 cryptomilk

It looks like it is a slot, it seems you can switch between 0 and 1.

 asn  (e) venv  ~  workspace  rockrobo  miio  mirobo raw-command get_persist_map_v1 1
Sending cmd get_persist_map_v1 with params 1
['retry']
 asn  (e) venv  ~  workspace  rockrobo  miio  mirobo raw-command get_persist_map_v1 0
Sending cmd get_persist_map_v1 with params 0
['map_upload_handler']
 asn  (e) venv  ~  workspace  rockrobo  miio  mirobo raw-command get_persist_map_v1 0
Sending cmd get_persist_map_v1 with params 0
['retry']
 asn  (e) venv  ~  workspace  rockrobo  miio  mirobo raw-command get_persist_map_v1 1
Sending cmd get_persist_map_v1 with params 1
['map_upload_handler']

cryptomilk avatar Apr 07 '19 09:04 cryptomilk

get_persist_map_v1 only works after save_map. If you do a reset_map it doesn't work anmyore.

cryptomilk avatar Apr 07 '19 09:04 cryptomilk

So how do you remove virtual walls and no-go zones?

Hypfer avatar Apr 08 '19 18:04 Hypfer

Any news on this, did someone figure out how to delete virtual walls or no-go zones, or how to reset all virtual walls + all no go-zones with some kind of reset (without loosing the peristant map)?

Maybe the original app doesn't delete single entities, but resets all and re-builds the other ones.

Thyraz avatar May 20 '19 12:05 Thyraz

If you want to remove all walls and zones:

{'from': '4', 'id': 666, 'method': 'save_map', 'params': []}

FeatureExpert avatar May 20 '19 18:05 FeatureExpert

If you want to remove one part, you parse the current map file, remove the part you don't want and call save_map with the params you want.

cryptomilk avatar May 21 '19 07:05 cryptomilk

Can we somehow edit map background in a user friendly way? What I mean is... e,g, when robot scans near a mirror - there are beams drawn on a map that go outside the room\house image (the screen taken from Valetudo, but it shouldn't matter). I'd like to clean up the map for it to look nicer. I have map json file downloaded, but it's 700kb of text\numbers, so really hard to track each point's coordinates. Thus some app/UI would be nice.

Shurov avatar Nov 14 '23 16:11 Shurov

This is nothing you can simply set in the request, nor is there an obvious way to avoid it. The Xiaomi cloud offers a basic bitmap with the colors including the reflections you see.

Besides that it offers the location of the various objects & tracks etc.

You might be able to create a client that does some smart things to the bitmap, to determine if it is part of a larger(largest) cloud of pixels or something, but that would be totally client dependent.

marcelrv avatar Nov 15 '23 07:11 marcelrv