Nothing happens when calibrating motors on Alex

Hi,

Nothing happens when calibrating Alex.

I have added the following, as per a similar case and a suggestion from duwudi. But it did not help:
from pitop import Pitop, alex_config
alex = Pitop.from_config(alex_config)

What is the FULL program to calibrate the Servo motors?

Thanks,
Guss H.

@designcode, welcome to the pi-top forums. Be careful because friendships and community with really awesome people is here. :smiley:

Try this:

from pitop import AlexRobot
from time import sleep

alex = AlexRobot()
alex.calibrate()

### NOTE: Then you can run a test to check the motors

# check one EncoderMotor
alex.left(0.1)
sleep(2)

# check the other EncoderMotor
alex.right(0.1)
sleep(2)

# then this should run both
alex.forward(0.1)
sleep(2)

Something like that what you are looking for?

1 Like

Hi @designcode

You can use what @Tom-B suggested or this:

from pitop import Pitop, alex_config

alex = Pitop.from_config(alex_config)
alex.pan_tilt.calibrate()

This is the recommended way from now on, the AlexRobot() class is legacy but can still be used and is basically equivelent. Remember to always run updates too, the SDK is being added to constantly!

@Tom-B by the way, the .left() and .right() commands do runs both motors, just in opposite directions :slightly_smiling_face:

In the method I proposed using to create an Alex Robot it would be alex.drive.left() - so there are some differences in usage, drive gives access to everything in the DriveController

1 Like

Right, of course. Sorry… I was thinking it turned with one motor and kept the other stationary.

Hi @duwudi,

This code snippet works. The lower servo motor does move. Thanks.

Questions:
1>> How can the upper servo motor (with camera attached) be calibrated? The below code procudes an error: AttributeError: ‘Pitop’ object has no attribute ‘tilt_servo’

from pitop import Pitop, alex_config
alex = Pitop.from_config(alex_config)
alex.tilt_servo.target_angle = 64
alex.pan_servo.target_angle = -10

2>> Where can we find details on the libraries (classes, methods and attributes)?

3>> Can the above code - for Alex Robot following a line - be run in VS Code? That way we can see the libraries (classes, methods and attributes)?

4>> The system does check for updates automatically at startup - so the SDK should be up-to-date. Right?

Thanks again.

Hi @Tom-B,
I will this code (for the encoder motors) later. Not there yet. Just starting with calibration of Servo motors.

Thanks,
GussH.

The tilt_servo and pan_servo are within the pan_tilt attribute, which is a PanTiltController(). Therefore, to access them you have to do it like this:

alex.pan_tilt.tilt_servo.target_angle = 64
alex.pan_tilt.pan_servo.target_angle = -10

If you call alex.pan_tilt.calibrate() you will be taken through calibration of both servo motors, just make sure they’re plugged into the correct ports on the Expansion Plate.

You can find the SDK on github, and our docs are here.

Please see this post to check if you have been impacted by an updater problem we recently found.

For Line Following, we also have a set of three tutorials on further.pi-top.com - you can find the first one here: https://further.pi-top.com/challenges/600be7f44d56f2001c1fd674

Finally, you can run everything in VS Code and if you’re running on the pi-top you should see details on the library. The one issue with this right now is the subclasses of the Pitop object (e.g. pan_tilt, drive, camera etc) are added at runtime when using the from_config method so the IDE won’t know that they exist. However, you can just create a pan_tilt object by doing:

from pitop import PanTiltController
pan_tilt = PanTiltController()

and you’ll be able to see all the information you need within an IDE. The from_config method was created to conveniently build an entire robot encapsulated in one “Pitop” object, the downside being your IDE won’t know its subclasses exist because they are added dynamically when the program is run.

Hope this helps!