|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright (c) 2018 Anki, Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License in the file LICENSE.txt or at |
| 8 | +# |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +"""Use custom objects to create a wall in front of Vector. |
| 18 | +
|
| 19 | +This example demonstrates how you can create custom objects in the world, and |
| 20 | +automatically have Vector path around them as if they are real obstacles. |
| 21 | +
|
| 22 | +It creates a wall in front of Vector and tells him to drive around it. |
| 23 | +He will plan a path to drive 200mm in front of himself after these objects are created. |
| 24 | +
|
| 25 | +The `show_3d_viewer=True` argument causes the 3D visualizer to open in a new |
| 26 | +window - this shows where Vector believes this imaginary object is. |
| 27 | +""" |
| 28 | + |
| 29 | +import anki_vector |
| 30 | +from anki_vector.util import Pose, degrees |
| 31 | + |
| 32 | + |
| 33 | +def main(): |
| 34 | + args = anki_vector.util.parse_command_args() |
| 35 | + with anki_vector.Robot(args.serial, |
| 36 | + show_3d_viewer=True, |
| 37 | + enable_nav_map_feed=True) as robot: |
| 38 | + robot.behavior.drive_off_charger() |
| 39 | + |
| 40 | + fixed_object = robot.world.create_custom_fixed_object(Pose(100, 0, 0, angle_z=degrees(0)), |
| 41 | + 10, 100, 100, relative_to_robot=True) |
| 42 | + if fixed_object: |
| 43 | + print("fixed custom object created successfully") |
| 44 | + |
| 45 | + robot.behavior.go_to_pose(Pose(200, 0, 0, angle_z=degrees(0)), relative_to_robot=True) |
| 46 | + robot.world.delete_custom_objects() |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + main() |
0 commit comments