Пример #1
0
    def step4_drop_stack_on_top(self):
        """
        Place the stack cube in the middle of the corner cube and right cube
        :return:
        """
        print('**step 4**')
        pickup_posn = self.corner_cube.pose.position
        right_posn = self.right_cube.pose.position

        # find an x coordinate that places cozmo at a position far enough away from the cubes such that when he
        # places the stack cube, it will land on top
        robot_x = pickup_posn.x - self.CUBE_SIZE * 1.6

        # find y coordinate for position in the middle of blocks
        middle_y = pickup_posn.y + (right_posn.y - pickup_posn.y) / 2
        # (assume an angle of 0 degrees as I'm not yet accounting for cubes that are rotated
        destination_pose = Pose(robot_x,
                                middle_y,
                                pickup_posn.z,
                                angle_z=degrees(0))
        go_to_destination_pose = self.robot.go_to_pose(destination_pose, num_retries=3)
        go_to_destination_pose.wait_for_completed()
        drop_stack = self.robot.place_object_on_ground_here(self.stack_cube, num_retries=3)
        drop_stack.wait_for_completed()

        self.stack_cube.set_lights(Light(on_color=Color(int_color=0xff00ffff), off_color=Color(int_color=0xff00ffff)))
        # I can't check for has_succeeded here because Cozmo won't think he's actually succeeded in dropping the cube
        # so let's just assume he was successful
        self.increment_step()
Пример #2
0
def setBackpackColors():
    global robot, delta, LIFT_POSITION

    print("Robot\'s pitch in radians: ")
    while (True):
        pitch = robot.pose_pitch.degrees
        pitch -= delta
        #print(pitch)

        backLights = Light(getColor(pitch))
        lightOff = Light(Color(rgb=(0, 0, 0)))
        if (pitch > 0.04):  #Forward
            robot.set_backpack_lights(lightOff, backLights, backLights,
                                      lightOff, lightOff)
        elif (pitch < -0.04):
            robot.set_backpack_lights(lightOff, lightOff, backLights,
                                      backLights, lightOff)
        else:
            robot.set_center_backpack_lights(backLights)

        if (math.fabs(robot._lift_position.ratio - LIFT_POSITION) > 0.05):
            print('Check detected!')
            break
        time.sleep(.1)
    robot.set_backpack_lights_off()
    return
Пример #3
0
class CubeColor:
    """ Class to define common colors to be used """
    CYAN = Color(name="cyan", int_color=0x00ffffff)
    MAGENTA = Color(name="magenta", int_color=0xff00ffff)
    YELLOW = Color(name="yellow", int_color=0xffff00ff)
    GREEN = Color(name="green", int_color=0x00ff00ff)
    RED = Color(name="red", int_color=0xff0000ff)
    BLUE = Color(name="blue", int_color=0x0000ffff)
    WHITE = Color(name="white", int_color=0xffffffff)
    OFF = Color(name="off")
Пример #4
0
class Colors:
    """ Class to define common colors to be used """
    CYAN = Light(Color(name="cyan", int_color=0x00ffffff))
    MAGENTA = Light(Color(name="magenta", int_color=0xff00ffff))
    YELLOW = Light(Color(name="yellow", int_color=0xffff00ff))
    GREEN = Light(Color(name="green", int_color=0x00ff00ff))
    RED = Light(Color(name="red", int_color=0xff0000ff))
    BLUE = Light(Color(name="blue", int_color=0x0000ffff))
    WHITE = Light(Color(name="white", int_color=0xffffffff))
    OFF = Light(Color(name="off"))
Пример #5
0
class CubeColor:

    CYAN = Color(name="magenta", int_color=0x00ffffff)
    MAGENTA = Color(name="magenta", int_color=0xff00ffff)
    YELLOW = Color(name="yellow", int_color=0xffff00ff)
    GREEN = Color(name="green", int_color=0x00ff00ff)
    RED = Color(name="red", int_color=0xff0000ff)
    BLUE = Color(name="blue", int_color=0x0000ffff)
    WHITE = Color(name="white", int_color=0xffffffff)
    OFF = Color(name="off")
Пример #6
0
def __get_light(red: int, green: int, blue: int) -> Light:
    """Convenience method to get a light from RGB values.

    :param red: Red 0 - 255.
    :param green: Green 0 - 255.
    :param blue: Blue 0 - 255.
    :return: A Light with the corresponding color.
    """
    color = Color(rgb=(red, green, blue))
    return Light(on_color=color)
Пример #7
0
 async def _cozmo_annonuce_weather_update_async(
         self,
         msg: str,
         title: str,
         rgb: Union[Tuple, None] = None,
         image_url: str = None) -> None:
     self.cozmo_state = CozmoStates.Anouncing
     if rgb:
         light = Light(Color(rgb=rgb)).flash()
         self._cozmo.cubes_change_lights(light)
         self._cozmo.backpack_change_light(light)
     await self._cozmo.random_positive_anim_async()
     await self._cozmo.say_async(title)
     await self._cozmo.say_async(msg)
     if image_url:
         await self._cozmo.show_image_from_url_async(image_url)
     if rgb:
         self._cozmo.turn_cubes_lights_off()
         self._cozmo.turn_backpack_light_off()
Пример #8
0
    def step2_place_right_cube_next_to_pickup(self):
        """
        Step 2: place the right cube next to the corner cube
        :return: None
        """
        print('**step 2**')


        pickup_posn = self.corner_cube.pose.position
        next_to_pickup_pose = Pose(pickup_posn.x - self.ROBOT_SIZE, pickup_posn.y - self.CUBE_SIZE - 14, pickup_posn.z,
                                   angle_z=degrees(0.0))
        go_to_next_to_pickup = self.robot.go_to_pose(next_to_pickup_pose)
        go_to_next_to_pickup.wait_for_completed()
        if go_to_next_to_pickup.has_succeeded:
            drop_action = self.robot.place_object_on_ground_here(self.right_cube, num_retries=3)
            drop_action.wait_for_completed()
            if drop_action.has_succeeded:
                purple_light = Color(int_color=0xff00ffff)
                self.corner_cube.set_lights(Light(on_color=purple_light, off_color=purple_light))
                self.right_cube.set_lights(Light(on_color=purple_light, off_color=purple_light))
                self.reset_pose()
                self.increment_step()
Пример #9
0
def calculateColor(abs_angle=0):
    '''
		This function will attribute a color corresponding to the error abs_angle.
		The maximun error is set at MAX_ANGLE
	'''
    # RGB tuple (0-255)
    global MAX_ANGLE
    slope = 255 / MAX_ANGLE

    if (abs_angle > 20):
        abs_angle = 20

    G = 255 - slope * abs_angle
    G = int(G)
    R = slope * abs_angle
    R = int(R)
    if (abs_angle <= MAX_ANGLE / 2):
        B = slope * abs_angle
    else:
        B = 255 - slope * abs_angle
    B = int(B)

    color = Color(rgb=(R, G, B))
    return color
Пример #10
0
# Set ENABLE_COLOR_BALANCING to False to skip the color_balance step
ENABLE_COLOR_BALANCING = True


# map_color_to_light (dict): maps each color name with its cozmo.lights.Light value.
# Red, green, and blue lights are already defined as constants in lights.py, 
# but we need to define our own custom Light for yellow.



# MODIFICATION FROM ORIGINAL SDK - Purple and Orange added.  Lights on cubes also change according to these values.

map_color_to_light = {
'green' : cozmo.lights.green_light, 
'yellow' : Light(Color(name='yellow', rgb = (255, 255, 0))), 
'blue' : cozmo.lights.blue_light, 
'red' : cozmo.lights.red_light,
'purple' : Light(Color(name='purple', rgb = (128, 0, 128))),
'orange' : Light(Color(name='orange', rgb = (255, 165, 0)))
}

# hsv_color_ranges (dict): map of color names to regions in HSV space.
# Instead of defining a color as a single (H, S, V) point, 
# colors are defined with a minimum and maximum value for H, S, and V.
# For example, a point with (H, S, V) = (200.0, 0.8, 0.95) falls entirely in the 'blue' region, 
# because 180.0 < 200.0 < 245.0, 0 < 0.8 < 1.0, and 0 < 0.95 < 1.0.
# A point with (H, S, V) = (88.0, 0.4, 0.9) does not fall exactly in one color region.
# But applying hsv_color_distance_sqr between this color and all the colors in hsv_color_ranges
# will show that (88.0, 0.4, 0.9) is closest to the 'green' region.
Пример #11
0
def cozmo_program(robot: cozmo.robot.Robot):

    # Les variables nécessaires
    min_number = 1
    max_number = 100
    number = 0
    turn = 0

    # Définir les couleurs
    light_yellow = Light(Color(name='yellow', rgb=(255, 255, 0)))
    light_green = Light(Color(name='green', rgb=(0, 255, 0)))
    light_blue = Light(Color(name='blue', rgb=(0, 0, 255)))

    # Tourner jusqu'a détecter un visage
    lookaround = robot.start_behavior(cozmo.behavior.BehaviorTypes.FindFaces)
    face = robot.world.wait_for_observed_face()
    lookaround.stop()

    # L'hummain trouvé est il connu ou inconnue
    robot.drive_straight(distance_mm(50), speed_mmps(50)).wait_for_completed()
    if (face.name != ""):
        robot.play_anim_trigger(
            cozmo.anim.Triggers.AcknowledgeFaceNamed).wait_for_completed()
        robot.say_text(face.name).wait_for_completed()
    else:
        robot.play_anim_trigger(
            cozmo.anim.Triggers.AcknowledgeFaceUnnamed).wait_for_completed()
        robot.say_text("Bonjour").wait_for_completed()

    # Donner les explications du jeu
    text = "Je vais deviner un nombre entre " + str(min_number) + " et " + str(
        max_number) + "."
    robot.say_text(text).wait_for_completed()
    robot.say_text("Bleu si plus grand.").wait_for_completed()
    robot.world.get_light_cube(LightCube1Id).set_lights(light_blue)
    robot.say_text("Jaune si plus petit.").wait_for_completed()
    robot.world.get_light_cube(LightCube2Id).set_lights(light_yellow)
    robot.say_text("Vert si j'ai trouvé.").wait_for_completed()
    robot.world.get_light_cube(LightCube3Id).set_lights(light_green)

    # Jouer l'animation Cozmo content
    robot.play_anim_trigger(
        cozmo.anim.Triggers.CodeLabHappy).wait_for_completed()
    robot.say_text("Vert quand tu es prêt.").wait_for_completed()

    # Attendre jusqu'a ce qu'un cube soit touché
    ready = False
    while ready is False:
        target = robot.world.wait_for(cozmo.objects.EvtObjectTapped)
        cube = robot.world.get_light_cube(target.obj.cube_id)
        ready = cube.cube_id is LightCube3Id

    # Générer un nombre aléatoire entre min_number et max_number
    number = random.randint(min_number, max_number)
    found = False
    cheated = False

    # Boucle de jeu
    while found is False and cheated is False:
        turn += 1
        robot.drive_straight(distance_mm(-30),
                             speed_mmps(50)).wait_for_completed()
        robot.play_anim_trigger(
            cozmo.anim.Triggers.CodeLabThinking).wait_for_completed()
        robot.say_text(str(number)).wait_for_completed()
        target = robot.world.wait_for(cozmo.objects.EvtObjectTapped)
        cube = robot.world.get_light_cube(target.obj.cube_id)
        # jouer l'animation suivat le cube touché
        if cube.cube_id is LightCube3Id:
            robot.play_anim_trigger(
                cozmo.anim.Triggers.CodeLabHappy).wait_for_completed()
            found = True
        elif cube.cube_id is LightCube1Id:
            robot.say_text("Plus grand ?").wait_for_completed()
            robot.play_anim_trigger(
                cozmo.anim.Triggers.CodeLabUnhappy).wait_for_completed()
            min_number = number + 1
        elif cube.cube_id is LightCube2Id:
            robot.say_text("Plus petit ?").wait_for_completed()
            robot.play_anim_trigger(
                cozmo.anim.Triggers.CodeLabUnhappy).wait_for_completed()
            max_number = number - 1
        else:
            cheated = True
        # Le joueur a t'il triché
        if max_number < min_number:
            cheated = True
        # Tenter de générer un nouveau nombre
        elif found is False:
            number = round((min_number + max_number) / 2)

    # Si COZMO à trouvé
    if found is True:
        text = str(turn) + " essais."
        robot.say_text(text).wait_for_completed()
        robot.play_anim_trigger(
            cozmo.anim.Triggers.CodeLabWin).wait_for_completed()
    else:
        robot.say_text("Tu as triché").wait_for_completed()
        robot.play_anim_trigger(
            cozmo.anim.Triggers.CodeLabFrustrated).wait_for_completed()
Пример #12
0
from cozmo.lights import Color, Light
try:
    from PIL import Image, ImageDraw, ImageStat
except ImportError:
    sys.exit(
        'Cannot import from PIL: Do `pip3 install --user Pillow` to install')

# Set ENABLE_COLOR_BALANCING to False to skip the color_balance step
ENABLE_COLOR_BALANCING = True

# map_color_to_light (dict): maps each color name with its cozmo.lights.Light value.
# Red, green, and blue lights are already defined as constants in lights.py,
# but we need to define our own custom Light for yellow.
map_color_to_light = {
    'green': cozmo.lights.green_light,
    'yellow': Light(Color(name='yellow', rgb=(255, 255, 0))),
    'blue': cozmo.lights.blue_light,
    'red': cozmo.lights.red_light
}

# hsv_color_ranges (dict): map of color names to regions in HSV space.
# Instead of defining a color as a single (H, S, V) point,
# colors are defined with a minimum and maximum value for H, S, and V.
# For example, a point with (H, S, V) = (200.0, 0.8, 0.95) falls entirely in the 'blue' region,
# because 180.0 < 200.0 < 245.0, 0 < 0.8 < 1.0, and 0 < 0.95 < 1.0.
# A point with (H, S, V) = (88.0, 0.4, 0.9) does not fall exactly in one color region.
# But applying hsv_color_distance_sqr between this color and all the colors in hsv_color_ranges
# will show that (88.0, 0.4, 0.9) is closest to the 'green' region.

hsv_color_ranges = {
    'red': (-20.0, 20.0, 0.5, 1.0, 0.5, 1.0),
Пример #13
0
class Colors:
    """ Class to define common colors to be used """
    GRAY_2 = Light(on_color=Color(name="gray", int_color=0x808080ff),
                   off_color=Color(name="black", int_color=0x00000000),
                   on_period_ms=1000,
                   off_period_ms=500)
    MAGENTA_2 = Light(on_color=Color(name="magenta", int_color=0xff00ffff),
                      off_color=Color(name="black", int_color=0x00000000),
                      on_period_ms=1000,
                      off_period_ms=500)
    YELLOW_2 = Light(on_color=Color(name="yellow", int_color=0xffff00ff),
                     off_color=Color(name="black", int_color=0x00000000),
                     on_period_ms=1000,
                     off_period_ms=500)
    GREEN_2 = Light(on_color=Color(name="green", int_color=0x00ff00ff),
                    off_color=Color(name="black", int_color=0x00000000),
                    on_period_ms=1000,
                    off_period_ms=500)
    RED_2 = Light(on_color=Color(name="red", int_color=0xff0000ff),
                  off_color=Color(name="black", int_color=0x00000000),
                  on_period_ms=1000,
                  off_period_ms=500)
    BLUE_2 = Light(on_color=Color(name="blue", int_color=0x00ffffff),
                   off_color=Color(name="black", int_color=0x00000000),
                   on_period_ms=1000,
                   off_period_ms=500)
    WHITE_2 = Light(on_color=Color(name="white", int_color=0xffffffff),
                    off_color=Color(name="black", int_color=0x00000000),
                    on_period_ms=1000,
                    off_period_ms=500)

    GRAY_1 = Light(on_color=Color(name="gray", int_color=0x808080ff),
                   off_color=Color(name="black", int_color=0x00000000),
                   on_period_ms=200,
                   off_period_ms=200)
    MAGENTA_1 = Light(on_color=Color(name="magenta", int_color=0xff00ffff),
                      off_color=Color(name="black", int_color=0x00000000),
                      on_period_ms=200,
                      off_period_ms=200)
    YELLOW_1 = Light(on_color=Color(name="yellow", int_color=0xffff00ff),
                     off_color=Color(name="black", int_color=0x00000000),
                     on_period_ms=200,
                     off_period_ms=200)
    GREEN_1 = Light(on_color=Color(name="green", int_color=0x00ff00ff),
                    off_color=Color(name="black", int_color=0x00000000),
                    on_period_ms=200,
                    off_period_ms=200)
    RED_1 = Light(on_color=Color(name="red", int_color=0xff0000ff),
                  off_color=Color(name="black", int_color=0x00000000),
                  on_period_ms=200,
                  off_period_ms=200)
    BLUE_1 = Light(on_color=Color(name="blue", int_color=0x00ffffff),
                   off_color=Color(name="black", int_color=0x00000000),
                   on_period_ms=200,
                   off_period_ms=200)
    WHITE_1 = Light(on_color=Color(name="white", int_color=0xffffffff),
                    off_color=Color(name="black", int_color=0x00000000),
                    on_period_ms=200,
                    off_period_ms=200)

    WHITE = Light(Color(name="white", int_color=0xffffffff))
    RED = Light(Color(name="red", int_color=0xff0000ff))
    GREEN = Light(Color(name="green", int_color=0x00ff00ff))
    BLUE = Light(Color(name="blue", int_color=0x00ffffff))
    MAGENTA = Light(Color(name="magenta", int_color=0xff00ffff))
    YELLOW = Light(Color(name="yellow", int_color=0xffff00ff))
    GRAY = Light(Color(name="gray", int_color=0x808080ff))
    OFF = Light(Color(name="off"))
Пример #14
0
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''Quick Tap - tap your cube as fast as possible when the colors match, but never tap on red!

The game ends when a player scores 5 points.
'''
import asyncio, random, sys, time

import cozmo

from cozmo.lights import blue_light, Color, green_light, Light, red_light, white_light, off_light
from cozmo.util import degrees, distance_mm, radians, speed_mmps

purple_light = Light(Color(name='purple', rgb=(255, 0, 255)))
yellow_light = Light(Color(name='yellow', rgb=(255, 255, 0)))

LIGHT_COLORS_LIST = [
    blue_light, green_light, purple_light, red_light, white_light, yellow_light
]

CHOOSE_CUBES_STATE = 'choose_cubes'  # If the game is in CHOOSE_CUBES_STATE, on_cube_tap assigns the player's cube.
GAME_STATE = 'game'  # If the game is in GAME_STATE, on_cube_tap registers the tap time of the players.

MAKE_BUZZERS_DIFFERENT_COLORS = 'MAKE_BUZZERS_DIFFERENT_COLORS'
MAKE_BUZZERS_RED = 'MAKE_BUZZERS_RED'
MAKE_BUZZERS_SAME_COLORS = 'MAKE_BUZZERS_SAME_COLORS'

# The buzzers have a 50% chance of displaying the same colors.
RATE_MAKE_BUZZERS_DIFFERENT_COLORS = 0.17  # The buzzers have a 17% chance of displaying different colors.
Пример #15
0
def cozmo_program(robot: cozmo.robot.Robot):

    # Définir la couleur jaune
    light_yellow = Light(Color(name='yellow', rgb=(255, 255, 0)))
    light_cyan = Light(Color(name='cyan', rgb=(0, 255, 255)))

    # Tourner jusqu'a détecter un visage
    lookaround = robot.start_behavior(cozmo.behavior.BehaviorTypes.FindFaces)
    face = robot.world.wait_for_observed_face()
    lookaround.stop()

    # Jouer l'animation du Chien
    robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()
    robot.play_anim_trigger(
        cozmo.anim.Triggers.CodeLabDog).wait_for_completed()

    # Se connecter aux différents cubes et les faire clignoter en jaune
    robot.world.get_light_cube(LightCube1Id).set_lights(light_yellow.flash())
    robot.world.get_light_cube(LightCube2Id).set_lights(light_yellow.flash())
    robot.world.get_light_cube(LightCube3Id).set_lights(light_yellow.flash())

    # Attendre jusqu'a ce qu'un cube soit touché
    target = robot.world.wait_for(cozmo.objects.EvtObjectTapped)
    cube = robot.world.get_light_cube(target.obj.cube_id)
    robot.world.get_light_cube(LightCube1Id).set_lights(light_cyan)
    robot.world.get_light_cube(LightCube2Id).set_lights(light_cyan)
    robot.world.get_light_cube(LightCube3Id).set_lights(light_cyan)
    cube.set_lights(light_yellow)

    # Tourner jusqu'a détecter le cube
    found = False
    lookaround = robot.start_behavior(
        cozmo.behavior.BehaviorTypes.LookAroundInPlace)
    while found is False:
        tcube = robot.world.wait_for_observed_light_cube(
            include_existing=False)
        found = tcube is cube
    lookaround.stop()

    # Rammasser le cube
    robot.dock_with_cube(cube,
                         approach_angle=cozmo.util.degrees(180),
                         num_retries=3).wait_for_completed()
    robot.move_lift(0.2)

    # Tourner jusqu'a détecter de nouvea le visage précédent
    found = False
    lookaround = robot.start_behavior(cozmo.behavior.BehaviorTypes.FindFaces)
    while found is False:
        tface = robot.world.wait_for_observed_face()
        found = tface is face
    lookaround.stop()

    # Se déplacer vers le visage poser le cube
    robot.drive_straight(distance_mm(200), speed_mmps(50)).wait_for_completed()
    robot.move_lift(-3)
    robot.move_lift(0)
    robot.drive_straight(distance_mm(-100),
                         speed_mmps(50)).wait_for_completed()
    robot.play_anim_trigger(
        cozmo.anim.Triggers.CodeLabDog).wait_for_completed()
Пример #16
0
#!/usr/bin/env python3

import asyncio

import cozmo
from cozmo.lights import blue_light, Color, green_light, Light, red_light, white_light, off_light
from cozmo.util import degrees, distance_mm, radians, speed_mmps

import globals

yellow_light = Light(Color(name='yellow', rgb=(255, 255, 0)))

rainbow_colors = [blue_light, red_light, green_light, yellow_light]


class BlinkyCube(cozmo.objects.LightCube):
    '''Same as a normal cube, plus extra methods specific to Quick Tap.'''
    def __init__(self, *a, **kw):
        super().__init__(*a, **kw)
        self._chaser = None
        self.mistake = globals.mistakes[self.cube_id - 1]

    def start_light_chaser(self, pause_time):
        '''Rotates four colors around the cube light corners in a continuous loop.

        Args:
            pause_time (float): the time awaited before moving the rotating lights
        '''
        if self._chaser:
            raise ValueError('Light chaser already running')
Пример #17
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import asyncio
import io
import random
import cozmo
from cozmo.lights import Color
from cozmo.objects import CustomObject, CustomObjectMarkers, CustomObjectTypes

CYAN = Color(name="cyan", int_color=0x00ffffff)
PINK = Color(name="magenta", int_color=0xff00ffff)
YELLOW = Color(name="yellow", int_color=0xffff00ff)
GREEN = Color(name="green", int_color=0x00ff00ff)
RED = Color(name="red", int_color=0xff0000ff)
BLUE = Color(name="blue", int_color=0x0000ffff)
WHITE = Color(name="white", int_color=0xffffffff)
OFF = Color(name="off")


class VisionCube(cozmo.objects.LightCube):
    def __init__(self, *a, **kw):
        super().__init__(*a, **kw)
        self._chaser = None
        self._cube = cozmo.objects.LightCube
        self._color = cozmo.lights.off
Пример #18
0
def cozmo_program(_robot: cozmo.robot.Robot):

    global idx1
    global idx2
    global idx3
    global robot
    global color

    idx1 = 0
    idx2 = 0
    idx3 = 0
    robot = _robot

    color = [
        Light(Color(rgb=(0, 0, 0))),
        Light(Color(rgb=(0, 0, 255))),
        Light(Color(rgb=(0, 255, 0))),
        Light(Color(rgb=(0, 255, 255))),
        Light(Color(rgb=(255, 0, 0))),
        Light(Color(rgb=(255, 0, 255))),
        Light(Color(rgb=(255, 255, 0))),
        Light(Color(rgb=(255, 255, 255)))
    ]

    robot.world.get_light_cube(LightCube1Id).set_lights(color[idx1])
    robot.world.get_light_cube(LightCube2Id).set_lights(color[idx2])
    robot.world.get_light_cube(LightCube3Id).set_lights(color[idx3])

    robot.play_anim_trigger(
        cozmo.anim.Triggers.BouncerIdeaToPlay).wait_for_completed()
    robot.say_text("Salut").wait_for_completed()
    robot.say_text("Nous allons jouer à Speed Cube").wait_for_completed()
    robot.say_text(
        "Ce jeu peut se jouer jusqu'à trois joueurs").wait_for_completed()
    robot.say_text("Le joueur 1 jouera avec le cube 1").wait_for_completed()
    robot.world.get_light_cube(LightCube1Id).set_lights(color[2].flash())
    time.sleep(1)
    robot.world.get_light_cube(LightCube1Id).set_lights(color[idx1])
    robot.say_text("Le joueur 2 jouera avec le cube 2").wait_for_completed()
    robot.world.get_light_cube(LightCube2Id).set_lights(color[2].flash())
    time.sleep(1)
    robot.world.get_light_cube(LightCube2Id).set_lights(color[idx2])
    robot.say_text("Le joueur 3 jouera avec le cube 3").wait_for_completed()
    robot.world.get_light_cube(LightCube3Id).set_lights(color[2].flash())
    time.sleep(1)
    robot.world.get_light_cube(LightCube3Id).set_lights(color[idx3])
    robot.say_text("Le premier qui aura tappé 7 fois le cube aura gagné !"
                   ).wait_for_completed()
    time.sleep(1)
    robot.say_text("Attention").wait_for_completed()
    time.sleep(1)
    robot.say_text("Prêt ?").wait_for_completed()
    time.sleep(1)
    robot.play_anim_trigger(
        cozmo.anim.Triggers.CodeLab123Go).wait_for_completed()

    robot.world.add_event_handler(cozmo.objects.EvtObjectTapped, cubeTapped)
    while idx1 < 7 and idx2 < 7 and idx3 < 7:
        time.sleep(0.01)

    robot.play_anim_trigger(
        cozmo.anim.Triggers.CodeLabHappy).wait_for_completed()
    if (idx1 == 7):
        robot.say_text("Vainqueur joueur 1 !").wait_for_completed()
    elif (idx2 == 7):
        robot.say_text("Vainqueur joueur 2 !").wait_for_completed()
    else:
        robot.say_text("Vainqueur joueur 3 !").wait_for_completed()

    robot.play_anim_trigger(
        cozmo.anim.Triggers.CodeLabWin).wait_for_completed()
Ce programme se veut un jeu de tennis se jouant à deux joueurs.
Il reprend les principes du jeu tennis disponnible à l'époque sur le
Microcomputer Training vendu dans les magasins Tandy au début des années
90.

'''

import time
import asyncio
import cozmo
from cozmo.objects import LightCube1Id, LightCube2Id, LightCube3Id
from cozmo.lights import Color, Light
from cozmo.util import degrees, distance_mm, speed_mmps

# Définir les couleurs
light_yellow = Light(Color(name='yellow', rgb=(255, 255, 0)))  # balle
light_gray = Light(Color(name='gray', rgb=(200, 200, 200)))  # filet
light_blue = Light(Color(name='blue', rgb=(0, 0, 255)))  # joueur2
light_red = Light(Color(name='red', rgb=(255, 0, 0)))  # joueur1
light_off = Light(Color(name='off', rgb=(0, 0, 0)))

robot = None

ball_position = 0
ball_speed = 0.5
ball_direction = 1

cube1 = None
cube2 = None
cube3 = None
Пример #20
0
import sys
from math import sqrt, atan2, pi

from cozmo.lights import green_light, red_light, blue_light, white_light, off_light, Color, Light
from cozmo.objects import CustomObjectMarkers, CustomObjectTypes, _CustomObjectType

#################
# DEFINE COLORS #
#################
brown_color = Color(name="brown", rgb=(80, 20, 0))
yellow_color = Color(name="yellow", rgb=(255, 255, 0))
orange_color = Color(name="orange", rgb=(255, 80, 0))
purple_color = Color(name="purple", rgb=(255, 0, 255))
teal_color = Color(name="teal", rgb=(0, 255, 255))

brown_light = Light(on_color=brown_color)
yellow_light = Light(on_color=yellow_color)
orange_light = Light(on_color=orange_color)
purple_light = Light(on_color=purple_color)
teal_light = Light(on_color=teal_color)

COLORS = [
    "red", "blue", "green", "brown", "yellow", "orange", "purple", "teal",
    "white", "off"
]
LIGHTS = [
    red_light, blue_light, green_light, brown_light, yellow_light,
    orange_light, purple_light, teal_light, white_light, off_light
]
LIGHTS_DICT = dict(zip(COLORS, LIGHTS))