• Week 15 (session 9)

    Sylvain04/11/2025 at 07:08 0 comments

    Before the class, I powered all the motors and tested them but there were some issues so I decided to test one servo at a time so I was able to observe what was the problem.

    I tested the second servo (the one for the shoulder) and it struggled to move when the direction of rotation changed but I had no idea why it did that, so I asked Vincent. He believed it was a software issue and told me to paste the code to Chatgpt to find the source of the problem. It turns out that my code increase the servos rotation by only 5° but sometimes this angle is too small to be detected so I needed an 'oscillation'. The purpose of the oscillation is to move slightly past the target angle when the servo is changing direction, then returning to the desired angle. It helps to overcome the servo's dead zone.

    Below is the code Chatgpt gave me.

    from machine import Pin, PWM
    import time
    
    # Nombre de servos
    NUM_SERVOS = 6
    
    # Définition des broches GPIO pour chaque servo
    SERVO_PINS = [15, 16, 17, 18, 19, 20]
    
    # Initialisation des servos
    servos = [PWM(Pin(pin)) for pin in SERVO_PINS]
    for servo in servos:
        servo.freq(50)  # Fréquence PWM pour les servos (50 Hz)
    
    # Angles initiaux des servos
    angles = [90] * NUM_SERVOS  # Tous les servos commencent à 90°
    
    # Fonction pour convertir un angle (0-180°) en signal PWM
    def set_angle(servo, angle):
        min_duty = 1638   # pour 0°
        max_duty = 8192   # pour 180°
        duty = int(min_duty + (angle / 180) * (max_duty - min_duty))
        servo.duty_u16(duty)
    
    # Appliquer la position initiale aux servos
    for i in range(NUM_SERVOS):
        set_angle(servos[i], angles[i])
    
    # Servo actif (par défaut, le premier)
    servo_index = 0  
    
    print("\n--- Contrôle des servos ---")
    print("Sélection du servo : [1-6]")
    print("Changer l'angle : [a] ↙  [q] ↗")
    print("Quitter : [x]\n")
    
    # Dernier angle utilisé pour détecter un changement de direction
    last_direction = None
    
    while True:
        command = input("Commande : ")
    
        if command in "123456":  # Sélectionner un servo actif
            servo_index = int(command) - 1
            print(f"➡ Servo {servo_index + 1} sélectionné")
    
        elif command == "a":  # Décrémenter l'angle
            new_angle = max(0, angles[servo_index] - 5)
    
            # Si changement de direction (vers le bas)
            if last_direction == "up":
                temp_angle = max(0, new_angle - 2)
                set_angle(servos[servo_index], temp_angle)
                time.sleep(0.1)
    
            angles[servo_index] = new_angle
            last_direction = "down"
    
        elif command == "q":  # Incrémenter l'angle
            new_angle = min(180, angles[servo_index] + 5)
    
            # Si changement de direction (vers le haut)
            if last_direction == "down":
                temp_angle = min(180, new_angle + 2)
                set_angle(servos[servo_index], temp_angle)
                time.sleep(0.1)
    
            angles[servo_index] = new_angle
            last_direction = "up"
    
        elif command == "x":  # Quitter
            break
    
        # Mettre à jour le servo actif
        set_angle(servos[servo_index], angles[servo_index])
        print(f"Servo {servo_index + 1}: {angles[servo_index]}°")
    
        time.sleep(0.1)  # Délai anti-spam
    

  • Week 14 (session 8)

    Sylvain04/04/2025 at 07:24 0 comments

    I thought I nearly finished the assembly of the arm last time but in fact the last steps took me more time than I anticipated. I needed to fix the last MG995 servo but I struggled with the screws. I also had to change one of the servos horn because it was the one from the Parallax and it wouldn't fit in the MG995 servo.

    I then tighten some screws because they were too loose and some part of the arm fell off.

    Once I finished the assembly I started to work on how to connect the cables but Vladimir told me that I first needed to make the arm move before thinking about cable management.

  • Week 13 (session 7)

    Sylvain03/28/2025 at 09:22 0 comments

    At the beginning of the class, I showed Vincent the first two rotations of the arm. We agreed that I could finish the assembly before the end of the session so I started working on it. We also talked about the way of controlling the servos because for now I control one servo at a time with my keyboard so the movements aren't smooth, but he told me that I could work on it once I will have finished the arm.

    I fixed 3 SG90 servo to create the wrist and the claw and then I added the last MG995 servo to this part. I didn't have enough time to complete the assembly but I only have to connect the two parts together, it will create the elbow of the arm.

  • Week 12 (session 6)

    Sylvain03/28/2025 at 09:02 0 comments

    I had finished to remove the supports of all the parts so I started to construct the arm. The first step was to fix a servo to the basis. I used Parallax servos that Nicolas gave me while waiting to receive the MG995 servos. They have the same technical specification but the length between the screw holes of the Parallax is a bit larger than the MG995's so I struggled a little. I then fixed the second servo that is the shoulder of the arm.

    To power the arm, I received a 5V 3A power supply and a DC jack connector to which I connected the 5V and GND cables. But before that, I needed to connect together both of the servos 5V and GND wires so Vladimir told me to solder them. I started by twisting together two cables to connect both servos, then I twisted a third wire that will be plugged in the DC jack connector. To make sure the connections will resist I solder the cables. This was for the GND connection but I don't think I had the correct technic to do it because for the 5V wires I struggled so I asked Vladimir and did it differently.

    I wanted to test the rotation of the two servos before the end of the class but didn't have enough time for it so I finished it at home and tested it. A few days later I received the MG995 servos and I replaced the Parallax before the next session.

  • Week 11 (session 5)

    Sylvain03/13/2025 at 09:41 0 comments

    I received 3 servos identical to the ones I need so I tested them to make sure they work properly. I tested them one at a time so I could power supply them with only the Raspberry and my computer.

    I also had all the parts I printed so I started removing the supports on the pieces.

  • Week 10 (session 4)

    Sylvain03/12/2025 at 13:18 0 comments

    I didn't do much during the Wednesday session but Vladimir told me I needed to start printing the pieces of the arm, so I downloaded all the parts on Bambu Studio and I prepared the plates to print them during the week. I had a total of 22 hours of impression so I divided it in 3.

  • Week 9 (session 3)

    Sylvain03/05/2025 at 13:52 0 comments

    Now that I have some basis to control servos with Python I need to work on the structure of the arm. Joon-Ho showed me a video of a robotic arm controlled by Arduino and an app, so I can take this project and upgrade it. He gave me the STEP files to print the parts of the arm.

    The first thing I did was to watch the video several times to see how it works and on what will I have to work on.

    My first issue is to control the servos with Python rather than Arduino. Then I have to adapt the basis to fit a Raspberry PI inside because with a terminal adapter it bigger than an Arduino card.

    I then brought home some cardboard to create a first shitty version of a robotic arm with servos controlled by Python. I was able to control 2 part of the arm just as the clamp even if it doesn't work properly.

  • Week 8 (Session 2)

    Sylvain02/25/2025 at 08:50 0 comments

    I picked up a Rasberry pi at L'Atelier to get familiar with it because it is the first time I use one. I firstly wanted to program in C++ but I really suck at programming so I thought Python was the best language to start. With Python, someone recommend me Thonny as an IDE so I downloaded it then set up the Rasberry pi on the App.

    My first objective was to light a LED only with my computer just to familiarize myself with the link between Python and the Rasberry. I then worked with buttons, a buzzer and a servo (SG90).

    I worked a little bit every day to be able to control the servo with 2 push buttons and this is the code I used :

    from machine import Pin, PWM
    import time
    
    servo = PWM(Pin(15))
    servo.freq(50)
    button1 = Pin(14, Pin.IN, Pin.PULL_UP)
    button2 = Pin(13, Pin.IN, Pin.PULL_UP)
    
    def set_angle(angle):
        min_us = 500
        max_us = 2500
        us = min_us + (angle / 180) * (max_us - min_us)
        duty = int((us / 20000) * 65535)  
        servo.duty_u16(duty)
    
    angle = 90
    
    try:
        while True:
            if button1.value():
                angle = min(angle + 5, 180)
                set_angle(angle)
                time.sleep(0.05)
            
            if button2.value():
                angle = max(angle - 5, 0)
                set_angle(angle)
                time.sleep(0.05)
    except KeyboardInterrupt:
        print("Arrêt du programme")
        set_angle(90)