-
Notifications
You must be signed in to change notification settings - Fork 1
Trinamics (Drive) Motors
The motors which drive the wheels of the robot are the Trinamics PD42-x-1670. These motors are Brushless DC Servo motors with a plethora of sensors and control schemes. You can set the torque, velocity, and position of the motor as well as read them back. The position control is absolute.
Now, let's talk about how to control one. First, you should set up You need to set up the RPi with the PiCan hat. This involves installing the standoffs to the RPi and then installing the PiCan. From here, you will use the screw terminal and install the CAN_H and CAN_L wires from your CAN bus. This should be a rail on a breadboard or the like. The CAN_H and CAN_L rails will also connect to the motor's CAN_H(pin 3) and CAN_L(pin 4) pins, respectively. More information about the four pins
If you are using a Pi that is already set up and connected, then you just need to run this command to initialize the can interface:
sudo /sbin/ip link set can0 up type can bitrate 1000000
From here, everything is controlled by our library. If you have the repo cloned, go to the lib folder and there is the "TrinamicsMotor.py" file. "from TrinamicsMotor import TrinamicsMotor" will import the class you need.
Now, you can instantiate the TrinamicsMotor class and control the motor.
Currently there are 6 functions:
- getTorque() - Return the torque(current) in milli-Amps drawn
- getVelocity() - Returns the current velocity of the motor in rpms. Note that this is an unsigned integer, so if you go negative, your are going MAX_INT - velocity... AKA a really big number. We'll find a way to fix this eventually. Maybe by: if(vel > 2 billion): vel -= MAX_INT... Or whatever the proper syntax for that is.
- getPosition() - Returns the absolute position of the motor. Reset every time the motor restarts.
- getVoltage() - Returns the voltage being supplied to the voltage in Volts.
- setVelocity(vel) - Sets the target velocity of the motor to vel. Uses a PID controller to ramp to this velocity. Should take no more than 1 second to reach the target velocity.
- setPosition(vel) - Ramps the velocity up to the max velocity and runs until the position reaches the desired position. Can be positive or negative