Quantcast
Viewing all articles
Browse latest Browse all 81

Tic36v4 - i2c- change max speed

Hello,

I’m trying to change the “Max speed” setting of my Tic, without using the "Tic Control Center.
A part of my code :

import tkinter as tk
from tkinter import ttk, Button, Label, StringVar
import pigpio
import time

class MonMoteur:
    def __init__(self, bus, addresse):
        # Initialisation de la connexion Pigpio
        self.pi = pigpio.pi()
        # Ouvrir la connexion I2C avec le bus et l'adresse spécifiés
        self.h = self.pi.i2c_open(bus, addresse)

    def get_max_speed(self):
        # Gets the "Maximum speed" variable from the Tic.
        b = self.get_variables(0x16, 4)
        bytes_list = list(b[1])  # Récupérer la partie bytearray
        max_speed = sum(value << (8 * i) for i, value in enumerate(bytes_list))
        if max_speed >= (1 << 31):
            max_speed -= (1 << 32)   
        return max_speed

    def set_max_speed(self, max_speed):
        # Sets the "Maximum speed" variable of the Tic.
        # Convert max_speed to Tic units (e.g., pulses per second)
        max_speed_units = int(max_speed)
        # Split the max_speed_units into bytes (little-endian)
        max_speed_bytes = [(max_speed_units >> i) & 0xFF for i in range(0, 32, 8)]
        # Construct the command to set the max speed
        command = [0x47] + max_speed_bytes
        self.pi.i2c_write_device(self.h, command)

addresseDuTic1 = 0x0E
bus = 3
Moteur1 = MonMoteur(bus, addresseDuTic1)
Moteur1.set_max_speed(10000000)

The “get_max_speed” function seems to be working well,
But I cannot manage to change the “Max speed” setting eventhough the signals looks fine to me.

If I’m checking in the TicControlCenter, the Max seed is still the same.
Any advices ? (I have the same problem with the “Current limit” setting)
Thanks a lot for the reading time Image may be NSFW.
Clik here to view.
:slight_smile:

Bastien

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 81

Trending Articles