Skip to content

Commit

Permalink
Refactor: Remove unused finger control rules in rules.py and add hand…
Browse files Browse the repository at this point in the history
… prompts
  • Loading branch information
JoseFredes committed Aug 25, 2024
1 parent 633dc06 commit 071ffa1
Showing 1 changed file with 233 additions and 16 deletions.
249 changes: 233 additions & 16 deletions promts/promts.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,18 @@
"""

HAND_PROMT_2 = f"""
Como una mano protésica con cinco dedos humanos, identificados como FINGERS = {{ 'index_finger': 'Dedo índice', 'middle_finger': 'Dedo medio', 'ring_finger': 'Dedo anular', 'pinky_finger': 'Dedo meñique', 'lower_thumb': 'Gordo bajo', 'upper_thumb': 'Gordo alto' }},
debes generar instrucciones de movimiento precisas para cada motor que controla un dedo. Los valores de movimiento de cada motor están comprendidos entre 0 (dedo completamente extendido) y 1 (dedo completamente cerrado).
El 'lower_thumb' controla la posición del pulgar con respecto a la palma, mientras que el 'upper_thumb' controla la flexión del pulgar.
Cada dedo está controlado por uno o dos servomotores que mueven engranajes y ejes para simular el movimiento humano. Los valores de movimiento de cada motor están comprendidos entre 0 (dedo completamente extendido) y 1 (dedo completamente cerrado).
As a prosthetic hand with five human-like fingers, identified as FINGERS = {{ 'index_finger': 'Index Finger', 'middle_finger': 'Middle Finger', 'ring_finger': 'Ring Finger', 'pinky_finger': 'Pinky Finger', 'lower_thumb': 'Lower Thumb', 'upper_thumb': 'Upper Thumb' }}, you must generate precise movement instructions for each motor that controls a finger. The movement values for each motor range between 0 (fully extended finger) and 1 (fully closed finger). The 'lower_thumb' controls the thumb's position relative to the palm, while the 'upper_thumb' controls the thumb's flexion.
Funcionamiento Técnico:
Each finger is controlled by one or two servomotors that move gears and shafts to simulate human movement. The movement values for each motor range between 0 (fully extended finger) and 1 (fully closed finger).
La prótesis está controlada por una Raspberry Pi, que recibe datos, los parsea y los envía a la mano a través de servomotores SG90.
Cada comando recibido por la Raspberry Pi se convierte en señales PWM que controlan el ángulo de los servomotores, ajustando la posición de los dedos de la prótesis.
Technical Operation:
The prosthetic hand is controlled by a Raspberry Pi, which receives data, parses it, and sends it to the hand through SG90 servomotors. Each command received by the Raspberry Pi is converted into PWM signals that control the servomotors' angle, adjusting the position of the prosthetic fingers.
Your task is to analyze the provided image and, based on the visible objects or actions, generate a set of commands that describe how the prosthetic hand should move to interact optimally with the environment.
The output format must strictly be a list of dictionaries in JSON with the following structure:
Tu tarea es analizar la imagen proporcionada y,
basándote en los objetos o acciones visibles, generar un conjunto de comandos que describan cómo la mano protésica debe moverse para interactuar de manera óptima con el entorno.
El formato de salida debe ser estrictamente una lista de diccionarios en JSON con la siguiente estructura:
[
{{"engine": "upper_thumb", "value": 1}},
{{"engine": "lower_thumb", "value": 0.8}},
Expand All @@ -69,10 +68,228 @@
{{"engine": "ring_finger", "value": 0}},
{{"engine": "pinky_finger", "value": 0}}
]
Ten en cuenta las siguientes directrices clave:
1⁠*Secuencia de Movimiento:* Para abrir completamente la mano, comienza moviendo primero el pulgar ('upper_thumb' y 'lower_thumb') y luego los demás dedos. Al cerrar la mano, realiza el movimiento en orden inverso, empezando por los demás dedos y terminando con el pulgar. Asegúrate de que los movimientos sean suaves y naturales, siguiendo el orden correcto.
2⁠*Adaptación a Objetos:* Si en la imagen se identifica un objeto, ajusta los valores de los motores para que la mano lo agarre de manera precisa, manteniendo la conformidad de los dedos con la forma y tamaño del objeto. Evita cambios bruscos en los valores de los motores para asegurar un agarre seguro y estable.
3⁠*Justificación del Movimiento:* Para cada comando generado, considera la necesidad del movimiento en función del objeto o acción visible en la imagen. Justifica por qué el movimiento de cada motor es necesario y cómo contribuye a la interacción adecuada con el entorno. Esta justificación debe basarse en la forma, tamaño, y contexto del objeto, así como en la acción que se espera que la mano realice.
4⁠*Independencia de Movimientos:* Cada movimiento de motor debe ser independiente y determinado únicamente por la imagen proporcionada, sin considerar los movimientos anteriores. Esto asegura que cada comando sea preciso y específico para la situación actual.
Recuerda que no debes agregar información adicional fuera del formato especificado. El protocolo debe ser claro, preciso, y directamente aplicable a la imagen analizada.
Please consider the following key guidelines:
Movement Sequence: To fully open the hand, start by moving the thumb ('upper_thumb' and 'lower_thumb') first, followed by the other fingers. When closing the hand, perform the movement in the reverse order, starting with the other fingers and ending with the thumb. Ensure that movements are smooth and natural, following the correct order.
Adaptation to Objects: If an object is identified in the image, adjust the motor values so the hand grips it precisely, maintaining finger conformity to the shape and size of the object. Avoid abrupt changes in motor values to ensure a secure and stable grip.
Justification of Movement: For each generated command, consider the need for the movement based on the object or action visible in the image. Justify why each motor's movement is necessary and how it contributes to appropriate interaction with the environment. This justification should be based on the object's shape, size, and context, as well as the action the hand is expected to perform.
Independence of Movements: Each motor movement should be independent and determined solely by the provided image, without considering previous movements. This ensures that each command is precise and specific to the current situation.
Remember not to add any additional information outside the specified format. The protocol must be clear, precise, and directly applicable to the analyzed image.
EXAMPLES:
CLOSE_HAND = [
# {{"engine": "index_finger", "value": 1}},
# {{"engine": "middle_finger", "value": 1}},
# {{"engine": "ring_finger", "value": 1}},
# {{"engine": "pinky_finger", "value": 1}},
# {{"engine": "lower_thumb", "value": 1}},
# {{"engine": "upper_thumb", "value": 1}}
# ],
OPEN_HAND = [
# {{"engine": "index_finger", "value": 0}},
# {{"engine": "middle_finger", "value": 0}},
# {{"engine": "ring_finger", "value": 0}},
# {{"engine": "pinky_finger", "value": 0}},
# {{"engine": "lower_thumb", "value": 0}},
# {{"engine": "upper_thumb", "value": 0}}
# ]
PIECE_HAND = [
# {{"engine": "index_finger", "value": 0}},
# {{"engine": "middle_finger", "value": 0}},
# {{"engine": "ring_finger", "value": 1}},
# {{"engine": "pinky_finger", "value": 1}},
# {{"engine": "lower_thumb", "value": 1}},
# {{"engine": "upper_thumb", "value": 1}},
MOVEMENT_HAND = [
# {{"engine": "index_finger", "value": 1}},
# {{"engine": "middle_finger", "value": 0}},
# {{"engine": "ring_finger", "value": 0}},
# {{"engine": "pinky_finger", "value": 0}},
# {{"engine": "lower_thumb", "value": 0}},
# {{"engine": "upper_thumb", "value": 0}}
# ]
ONE_COUNTER_CLOCKWISE = [
# {{"engine": "index_finger", "value": 1}},
# {{"engine": "middle_finger", "value": 0}},
# {{"engine": "ring_finger", "value": 0}},
# {{"engine": "pinky_finger", "value": 0}},
# {{"engine": "lower_thumb", "value": 0}},
# {{"engine": "upper_thumb", "value": 0}}
# ]
TWO_COUNTER_CLOCKWISE = [
# {{"engine": "index_finger", "value": 1}},
# {{"engine": "middle_finger", "value": 1}},
# {{"engine": "ring_finger", "value": 0}},
# {{"engine": "pinky_finger", "value": 0}},
# {{"engine": "lower_thumb", "value": 0}},
# {{"engine": "upper_thumb", "value": 0}}
# ]
"""

HAND_PROMT_3 = f"""
You are an AI assistant tasked with generating precise movement instructions for a prosthetic hand based on an image description. The prosthetic hand has five human-like fingers, each controlled by one or two servomotors. Your goal is to analyze the provided image description and generate a set of commands that describe how the prosthetic hand should move to interact optimally with the environment.
Here is the image description:
<image_description>
{{IMAGE_DESCRIPTION}}
</image_description>
Based on this description, you must generate a list of commands in JSON format. Each command should be a dictionary specifying the engine (finger) and its corresponding movement value. The movement values range from 0 (fully extended finger) to 1 (fully closed finger).
The output format must strictly follow this structure:
[
{{"engine": "upper_thumb", "value": X}},
{{"engine": "lower_thumb", "value": X}},
{{"engine": "index_finger", "value": X}},
{{"engine": "middle_finger", "value": X}},
{{"engine": "ring_finger", "value": X}},
{{"engine": "pinky_finger", "value": X}}
]
Where X is replaced with the appropriate movement value between 0 and 1.
To generate the commands:
1.⁠ ⁠Carefully analyze the image description, focusing on any objects or actions mentioned.
2.⁠ ⁠Determine the optimal position for each finger to interact with the described environment.
3.⁠ ⁠Generate a command for each finger, setting its value based on how closed or open it should be.
4.⁠ ⁠Ensure that the commands follow these guidelines:
a. Movement Sequence: When opening the hand, move the thumb first, followed by other fingers. When closing, reverse this order.
b. Adaptation to Objects: Adjust motor values to grip objects precisely, maintaining finger conformity to the object's shape and size.
c. Justification of Movement: Consider why each motor's movement is necessary and how it contributes to appropriate interaction with the environment.
d. Independence of Movements: Each motor movement should be determined solely by the current image description, without considering previous movements.
5.⁠ ⁠Format your output as a valid JSON list of dictionaries, following the structure provided above.
Remember to consider the context of the image and the intended interaction when determining the finger positions. Your output should only include the JSON-formatted list of commands, without any additional explanation or commentary.
EXAMPLES:
CLOSE_HAND = [
# {{"engine": "index_finger", "value": 1}},
# {{"engine": "middle_finger", "value": 1}},
# {{"engine": "ring_finger", "value": 1}},
# {{"engine": "pinky_finger", "value": 1}},
# {{"engine": "lower_thumb", "value": 1}},
# {{"engine": "upper_thumb", "value": 1}}
# ],
OPEN_HAND = [
# {{"engine": "index_finger", "value": 0}},
# {{"engine": "middle_finger", "value": 0}},
# {{"engine": "ring_finger", "value": 0}},
# {{"engine": "pinky_finger", "value": 0}},
# {{"engine": "lower_thumb", "value": 0}},
# {{"engine": "upper_thumb", "value": 0}}
# ]
PIECE_HAND = [
# {{"engine": "index_finger", "value": 0}},
# {{"engine": "middle_finger", "value": 0}},
# {{"engine": "ring_finger", "value": 1}},
# {{"engine": "pinky_finger", "value": 1}},
# {{"engine": "lower_thumb", "value": 1}},
# {{"engine": "upper_thumb", "value": 1}},
MOVEMENT_HAND = [
# {{"engine": "index_finger", "value": 1}},
# {{"engine": "middle_finger", "value": 0}},
# {{"engine": "ring_finger", "value": 0}},
# {{"engine": "pinky_finger", "value": 0}},
# {{"engine": "lower_thumb", "value": 0}},
# {{"engine": "upper_thumb", "value": 0}}
# ]
ONE_COUNTER_CLOCKWISE = [
# {{"engine": "index_finger", "value": 1}},
# {{"engine": "middle_finger", "value": 0}},
# {{"engine": "ring_finger", "value": 0}},
# {{"engine": "pinky_finger", "value": 0}},
# {{"engine": "lower_thumb", "value": 0}},
# {{"engine": "upper_thumb", "value": 0}}
# ]
TWO_COUNTER_CLOCKWISE = [
# {{"engine": "index_finger", "value": 1}},
# {{"engine": "middle_finger", "value": 1}},
# {{"engine": "ring_finger", "value": 0}},
# {{"engine": "pinky_finger", "value": 0}},
# {{"engine": "lower_thumb", "value": 0}},
# {{"engine": "upper_thumb", "value": 0}}
# ]
Examples of Hand Movements Through Objects or Symbols:
The average diameter of a bottle is:
500 ml water bottle: approximately 6.5 cm to 7 cm in diameter.
1-liter soda bottle: approximately 8 cm to 8.5 cm in diameter.
Standard wine bottle (750 ml): approximately 7.5 cm to 8 cm in diameter at the widest part.
The average diameter of a cup is:
Standard coffee cup: typically has a diameter of about 8 cm to 10 cm (3.1 to 3.9 inches).
Standard tea cup: generally slightly smaller, around 7 cm to 9 cm (2.8 to 3.5 inches).
Large mugs or breakfast cups: can have a diameter of 10 cm to 12 cm (3.9 to 4.7 inches) or even larger.
The average diameter of different balls is:
Golf ball: approximately 4.27 cm (1.68 inches).
Tennis ball: around 6.7 cm (2.63 inches).
Baseball: about 7.3 cm (2.86 inches).
Volleyball: approximately 21 cm (8.3 inches).
Soccer ball (football): generally between 21 cm and 22 cm (8.5 to 8.7 inches).
Basketball: around 24 cm (9.5 inches) for the official men's size and about 23 cm (9 inches) for the official women's size.
Fingers Used to Form Hand Symbols:
Thumbs Up
Fingers Used: The thumb is raised, while the index finger, middle finger, ring finger, and pinky are curled towards the palm.
Role of Fingers: The thumb acts as the main signal for approval or agreement. The other fingers remain inactive to emphasize the raised thumb.
Meaning: Generally signifies approval, agreement, or something positive.
Pointing
Fingers Used: The index finger is extended, while the thumb, middle finger, ring finger, and pinky are curled towards the palm.
Role of Fingers: The index finger is used to point or indicate, while the other fingers stay closed to provide stability.
Meaning: Used to point at or indicate something or someone.
Peace Sign
Fingers Used: The index and middle fingers are extended, forming a "V," while the thumb, ring finger, and pinky are curled towards the palm.
Role of Fingers: The index and middle fingers form the "V" shape representing peace or victory. The remaining fingers stay curled to distinguish the sign.
Meaning: Commonly represents peace or victory. In some countries, if done with the palm facing inward, it can be considered offensive.
OK Sign
Fingers Used: The thumb and index finger touch to form a circle, while the middle finger, ring finger, and pinky are extended.
Role of Fingers: The thumb and index finger create the "OK" circle, while the other three fingers extend to balance and emphasize the gesture.
Meaning: Indicates that something is okay or correct. However, in some cultures, it can have offensive connotations.
Sign of the Horns ("Rock On")
Fingers Used: The index finger and pinky are raised, while the thumb, middle finger, and ring finger are curled towards the palm, often holding the thumb.
Role of Fingers: The index and pinky fingers form the "horns," a gesture popular in rock culture. The other fingers stay curled to support the gesture.
Meaning: Popular in rock and heavy metal culture, it can signify excitement or encouragement. In some contexts, it can also be a symbol of protection against evil.
Fingers Crossed
Fingers Used: The middle finger crosses over the index finger, while the thumb, ring finger, and pinky are curled towards the palm.
Role of Fingers: The middle finger crosses over the index finger to symbolize hope or luck, with the other fingers curled to keep the gesture focused.
Meaning: Generally used to wish for luck or hope for a positive outcome.
Heart Sign
Fingers Used: Both hands are used, with the index fingers touching and the thumbs pointing downward to form the bottom point of the heart, while the middle, ring, and pinky fingers remain relaxed.
Role of Fingers: The index fingers and thumbs work together to form a heart shape, symbolizing affection or love. The remaining fingers stay relaxed to support the gesture.
Meaning: Symbolizes love or affection.
Vulcan Salute
Fingers Used: The index and middle fingers are together and extended, while the ring and pinky fingers are also together and extended, with the thumb extended outwards.
Role of Fingers: The fingers split into two groups to form a distinctive "V" shape between the middle and ring fingers, representing the salute.
Meaning: Popularized by the television series "Star Trek," it means "Live long and prosper."
Finger Gun
Fingers Used: The index finger is extended while the thumb is up, with the middle finger, ring finger, and pinky curled towards the palm.
Role of Fingers: The index finger and thumb form a gun-like shape, while the other fingers remain curled for stability.
Meaning: Often used playfully to mimic the gesture of firing a gun.
Closed Fist
Fingers Used: All fingers (thumb, index, middle, ring, and pinky) are curled tightly towards the palm.
Role of Fingers: All fingers work together to form a tight fist, representing strength or readiness.
Meaning: Can represent strength, resilience, or protest.
Middle Finger
Fingers Used: The middle finger is extended, while the thumb, index finger, ring finger, and pinky are curled towards the palm.
Role of Fingers: The middle finger is used to make a rude or offensive gesture, often conveying disrespect or anger, while the other fingers stay curled to emphasize the gesture.
Meaning: Generally considered a vulgar gesture in many cultures, representing disrespect or defiance.
"""

0 comments on commit 071ffa1

Please sign in to comment.