ddcontroller package
Submodules
ddcontroller.ddcontroller module
- class ddcontroller.ddcontroller.DDRobot(config_path='/opt/ddcontroller/config/default.yaml', debug=False)[source]
Bases:
object
- define_global_position(position)[source]
Define the global position of the robot.
This method sets the global position of the robot as an attribute of the DDRobot object.
- Args:
position (list): A list containing the x and y position of the robot.
- Returns:
list: The global position of the robot.
- define_heading(heading)[source]
Define the heading of the robot.
This method defines the heading of the robot by taking the arctangent of the sine and cosine of the input heading, constraining the heading to be between -pi and pi. The defined heading is then stored as an attribute of the DDRobot object and returned.
- Args:
heading (float): The heading of the robot in radians.
- Returns:
float: The defined heading of the robot in radians, constrained to be between -pi and pi.
- get_angular_velocity()[source]
Get the angular velocity of the robot.
This method returns the angular velocity of the robot as an attribute of the DDRobot object.
- Returns:
float: The angular velocity of the robot, in radians per second.
- get_global_position()[source]
Get the global position of the robot.
This method returns the global position of the robot as an attribute of the DDRobot object.
- Returns:
list: The global position of the robot, as a list containing the x and y position.
- get_heading()[source]
Get the heading of the robot.
This method returns the heading of the robot as an attribute of the DDRobot object.
- Returns:
float: The heading of the robot in radians.
- get_linear_velocity()[source]
Get the linear velocity of the robot.
This method returns the linear velocity of the robot as an attribute of the DDRobot object.
- Returns:
float: The linear velocity of the robot, in meters per second.
- get_motion()[source]
Calculate and return the current linear and angular velocities of the robot.
- Returns:
list: A list of two floats, representing the linear and angular velocities of the robot, in that order.
- go_to(target_position, tolerance=0.1, max_linear_velocity=None, max_angular_velocity=None, backwards=False)[source]
Moves the robot to the specified target position using a position controller. The robot will continue to move towards the target position until it is within the specified tolerance.
- Args:
target_position (list): The target position as a 2-element list [x, y] in global coordinates. tolerance (float, optional): The tolerance for reaching the target position in meters. Defaults to 0.1. max_linear_velocity (float, optional): The maximum linear velocity the robot will use to reach the target position in m/s. If not provided, the default value specified in the configuration file will be used. max_angular_velocity (float, optional): The maximum angular velocity the robot will use to reach the target position in rad/s. If not provided, the default value specified in the configuration file will be used. backwards (bool, optional): Whether the robot should move backwards to reach the target position. Defaults to False.
- set_angular_velocity(angular_velocity)[source]
Set the target angular velocity for the robot.
- Args:
angular_velocity (float): The desired angular velocity of the robot in radians per second.
- Returns:
list: The current target motion of the robot, where the first element is the linear velocity and the second element is the angular velocity.
- set_heading(target_heading, max_angular_velocity=None)[source]
Set the heading of the robot.
This method sets the target heading of the robot by taking the arctangent of the sine and cosine of the input heading, constraining the heading to be between -pi and pi. The maximum angular velocity of the robot can also be set as an optional parameter. The control level of the robot is set to 2, indicating that heading control is active.
- Args:
target_heading (float): The target heading of the robot in radians. max_angular_velocity (float, optional): The maximum angular velocity of the robot in radians per second. Defaults to None.
- set_linear_velocity(linear_velocity)[source]
Set the desired linear velocity of the robot.
- Args:
linear_velocity (float): The linear velocity to set in meters per second.
- Returns:
list: The updated target motion of the robot.
- set_motion(target_motion)[source]
Set the target linear and angular velocities for the robot.
- Args:
- target_motion (list): A list containing the target linear velocity (m/s) as the first element
and the target angular velocity (rad/s) as the second element.
- Returns:
numpy.ndarray: An array containing the target angular velocities (rad/s) for the left and right wheels.
ddcontroller.motor module
- class ddcontroller.motor.Motor(pins, pwm_frequency, initial_duty=0, decay_mode='FAST', invert=False, rpm=200)[source]
Bases:
object
- set_duty(duty)[source]
Sets the duty cycle of the PWM signal.
- Args:
duty (float): The new duty cycle of the PWM signal, from -1 to 1.
ddcontroller.wheels module
- class ddcontroller.wheels.Wheel(motor_pins, pwm_frequency, i2c_bus, encoder_address, wheel_radius, motor_pulley_teeth, wheel_pulley_teeth, motor_decay_mode='FAST', invert_motor=False, invert_encoder=False, closed_loop=False, Kp=0, Ki=0, Kd=0)[source]
Bases:
object
- get_angular_velocity()[source]
Get the current angular velocity of the wheel.
This method calculates and returns the current angular velocity of the wheel, in radians per second, based on the rotation of the wheel and the elapsed time between measurements.
- Returns:
float: The current angular velocity of the wheel.
- get_linear_velocity()[source]
Get the current linear velocity of the wheel.
This method calculates and returns the current linear velocity of the wheel, in meters per second, based on the distance traveled by the wheel and the elapsed time between measurements.
- Returns:
float: The current linear velocity of the wheel.
- get_rotation()[source]
Get the rotation of the wheel.
This method calculates and returns the rotation of the wheel, in ticks, based on the positions of the encoder at two different points in time. It also accounts for rollover, where the encoder position resets after reaching a certain value. The rotation is calculated by taking the difference between the encoder positions and applying a pulley ratio to convert from motor pulley rotation to wheel rotation.
- Returns:
int: The rotation of the wheel, in ticks.
- get_travel()[source]
Get the distance traveled by the wheel.
This method calculates and returns the distance traveled by the wheel, in meters, based on the rotation of the wheel and the radius of the wheel.
- Returns:
float: The distance traveled by the wheel.
- set_angular_velocity(angular_velocity)[source]
Set the target angular velocity of the wheel.
This method sets the target angular velocity of the wheel, which is used to control the speed of the motor. The motor’s duty cycle is adjusted based on the target angular velocity, using either open loop or closed loop control.
- Args:
angular_velocity (float): The target angular velocity to set, in radians per second.