How to test if the GoPiGo motors are running?

Is there a way to check if the GoPiGo motors are actually running, if the car is driving?

2 Likes

There is a way to read the wheel encoders, (which I don’t remember).  If the encoder values are changing, the wheels are moving.

You will have to do a search for the easygopigo libraries on-line as there are functions that return the encoder values.

1 Like

Thanks a lot!
Yes, looking through the code I find that gopigi.enc_read(0) and gopigo.enc_read(1) read the wheel encoders.

2 Likes
def get_motor_status(self, port):
    """
    Read a motor status
    Keyword arguments:
    port -- The motor port (one at a time). MOTOR_LEFT or MOTOR_RIGHT.
    Returns a list:
        flags -- 8-bits of bit-flags that indicate motor status:
            bit 0 -- LOW_VOLTAGE_FLOAT - The motors are automatically disabled because the battery voltage is too low
            bit 1 -- OVERLOADED - The motors aren't close to the target (applies to position control and dps speed control).
        power -- the raw PWM power in percent (-100 to 100)
        encoder -- The encoder position
        dps -- The current speed in Degrees Per Second
    """
    if port == self.MOTOR_LEFT:
        message_type = self.SPI_MESSAGE_TYPE.GET_MOTOR_STATUS_LEFT
    elif port == self.MOTOR_RIGHT:
        message_type = self.SPI_MESSAGE_TYPE.GET_MOTOR_STATUS_RIGHT
    else:
        raise IOError("get_motor_status error. Must be one motor port at a time. MOTOR_LEFT or MOTOR_RIGHT.")
        return
1 Like

Is that an old GoPiGo? The current GoPiGo3 API for encoders is:

def get_motor_encoder(self, port):
    """
    Read a motor encoder in degrees
    Keyword arguments:
    port -- The motor port (one at a time). MOTOR_LEFT or MOTOR_RIGHT.
    Returns the encoder position in degrees
    """
    if port == self.MOTOR_LEFT:
        message_type = self.SPI_MESSAGE_TYPE.GET_MOTOR_ENCODER_LEFT
    elif port == self.MOTOR_RIGHT:
        message_type = self.SPI_MESSAGE_TYPE.GET_MOTOR_ENCODER_RIGHT
    else:
        raise IOError("Port(s) unsupported. Must be one at a time.")
        return 0

    encoder = self.spi_read_32(message_type)
    if encoder & 0x80000000:
        encoder = int(encoder - 0x100000000)
    return int(encoder / self.MOTOR_TICKS_PER_DEGREE)
1 Like

I have the old one, GoPiGo2, bought in 2017.

2 Likes

In that case, to tell if motors are running use the read_motor_speed() API:

def read_motor_speed():
	write_i2c_block(read_motor_speed_cmd, [unused,unused,unused])
	try:
		s1=i2c.read_8()
		s2=i2c.read_8()
	except IOError:
		return [-1,-1]
	return [s1,s2]
1 Like