-
Notifications
You must be signed in to change notification settings - Fork 6
5. Classes description
Use to import the classes for the electronic parts control.
from proteas_lib import controlUse to import the classes for the computer vision applications.
from proteas_lib import visionInitiates the control library, Should be used every time after the import of the control library.
control.start_lib() Clean up the GPIO pin parameters, should me used every time in the end of the program.
control.clean()That class used to control dc motor with PWM.
motor_a = control.motor(speed_pin,terma_pin,termb_pin) # User selected pins default frequency 10000 Hz and DC 70%
#or
motor_a = control.motor(speed_pin,terma_pin,termb_pin,freq=10000,dc=70) # User selected pins,frequency and DC
#functions
motor_a.move() # The motor moves forward by default
#or
motor_a.move(direction="reverse") # User selected direction "forward"/"reverse"
motor_a.stop() # Stops the rotation of the motor
motor_a.set_speed(speed=50) # Change the motor default speed 0-100%
motor_a.control_speed(speed=90) # Change dynamically the motor speed 0-100%That class used to take measurements from odometer sensors.
odometer_1 = control.odometer(pin) # Deafult 20 lines sensor disc,yser selected pin
#or
odometer_1 = control.odometer(pin,sensor_disc=20) # User selected lines for sensor disc
#functions
odometer_1.get_state() # Returns realtime the state of the sensor, 0/1 or True/False
odometer_1.get_steps() # Return the number of the steps(sensor disc activations)
odometer_1.get_revolutions() # Return the number of the revolutions of the wheel
odometer_1.get_distance(wheel_diameter=6.6,precision = 2)# Returns the distance traveled the robot in cm with default wheel diameter 6.6 cm and precision 2 for the value of the disatnce
odometer_1.reset() # Reset the revolutions counterThat class used to measure distance using a ultrasonic sensor.
ultra_1 = control.ultrasonic_sensor() # Default echo pin 14 and trigger pin 15
#or
ultra_1 = control.ultrasonic_sensor(echo_pin=14,trig_pin=15) # User selected pins
#functions
ultra_1.get_distance() # Return distance in cmThat class used for buttons with software pull up activated.
button_1() = control.button() # Default pin 18
#or
button_1() = control.button(pin = 18) # User selected pin
#functions
button_1.get_state() #Return the state of the pin, 0/1 or True/FalseThat class used for input eg. noise sensor, digital light sensor or every electronic circuit with digital output. Also you can use that class for the IR obstacle sensors.
noise_1 = control.gen_input() # Default pin 4
#or
noise_1 = control.gen_input(pin=4) # User selected pin
#functions
noise_1.get_state() #Return the state of the pin, 0/1 or True/FalseThat class used for output eg. led (with proper resistor 330 ohms), relay shield or every electronic circuit with digital input.
led_1 = control.gen_output() # Default pin 5
#or
led_1 = control.gen_output(pin=5) # User selected pin
#functions
led_1.set_on() #Power on the pin
led_1.set_off() #Power off the pinThat class used to receive measurements of acceleration and gyro from the MPU6050 sensor .
mpu = control.accelerometer() # Deafault address 0x68
#or
mpu = control.accelerometer(address=0x68) # User selected address
#functions
mpu.get_acceleration() # By default return 3 values x,y,z
#or
mpu.get_acceleration(dimension = "all") # User select "all","x","y","z"
mpu.get_gyro() # By default return 3 values x,y,z
#or
mpu.get_gyro(dimension = "all") # User select "all","x","y","z"That class used to control servo motor.
servo_1 = control.servo(pin=24) # User selected pin
#functions
servo_1.set_angle(angle=25) # User selected andgle in degreesThat class used for Nokia 5110 screen control.
main_screen = control.screen() # Default pins SCLK = 21,DIN = 20,DC = 16,RST =7,CS = 12
#or
main_screen = control.screen(SCLK = 21,DIN = 20,DC = 16,RST =7,CS = 12) # User selected pins
#functions
main_screen.ip_screen() # Print on the screen the ip of the robot
main_screen.print_text(text_list) # Take as input a list of 5 strings eg. text_list=['one','two',..,'five'] and prints every element of the list in a row. The row selected with the index number of the element.A inverse kinematics class to control the the vertical join of the robotic arm.
arm_control = control.arm_2dof(a1=100,a2=100) # Default lenght for every part of the arm
#functions
arm_control.calculate_angle(x,y) #Takes as input the desired destination for the arm and return the angles for the joins A PID controller class. Offers high precision control in many components. Before use PID please make a research about the usage and the parameters.
motor_pid = PID(KP=0,KI=0,KD=0)# By default PID is deactivated
# functions
motor_pid.pid_calc(desired_value,actual_value,start_time,end_time) #Return the value for the component
motor_pid.update_pid(KP,KI,KD) # Upates the parameters and reset the PID mesurments
motor_pid.reset_pid() # Reset the PID mesurmentsThat class used to store multiple measurements.
speed_data = control.data_logger()
#functions
speed_data.store_value(y,x) #Store eg. speed and time
speed_data.get_size() #Return how many rows of data collected
speed_data.draw_graph(type = "line")# Draws a graph from the collected data. Default parameter "line" for line graph or "points" for points graph
speed_data.clean_data() #Remove all the recorded measurements
speed_data.save_image(output="figure.png") #Saves the graph as png
speed_data.save_pdf(output="figure.pdf") #Saves the graph as pdfA timer class.
timer1 = control.timer()
#functions
timer1.start_timer() # Use it to start the time or reset the timer
timer1.elapsed() # Print the elasped time
timer1.get_elapsed() # Return the elasped timeThat class used to detect aruco artifacts in 6X6 size. That artifacts is special images and looks like with QR-code. The robot easy detect that images using the camera in any angle and light condition. Every artifact has a unique number.
aruco = vision.aruco_find()
# use the follow sequence
aruco.detect_artifacts(image) # Use for import a image eg. from camera, can return a new image with all the artifacts marked
aruco.find(ar_id) # User defined number for detection
final = aruco.mark_frame(frame) # Mark the location of the artifact on the image. Return a new image with the selected artifact number marked
#functions
aruco.get_pos()# Return the position of the selected artifact on the image
aruco.get_rect() #Return the size of the selected artifact
That class used initialize the camera and can return images from it.
cam_1 = vision.camera(camera=0)# User selected camera
#functions
frame = cam_1.take_frame() # Return a captured image
cam_1.stop() # Releases the camera, use it in the end of your codeThat class creates a image preview window or canvas.
canvas = vision.show_image(jupyter=True) # Default parameter for Jupyter slow frame rate. If you use directly on python script set false the parameter and a opencv image windows would be appear.
#functions
canvas.preview(frame) # Take as input a image
canvas.clear() # Use it only for direct usage of the class from a scriptThat class can detect faces on a image.
face = vision.face_detection()
#functions
frame = face.detect_face(frame) # Detect the position of the faces on image, can return an image with the faces marked
face.get_faces() # Return the number of the on the image
face.get_pos() # Return the position of the face on the image
face.get_rect() #Return the size of the faceThat class used to return direction to the robot about the center of the target eg. face
dog_1 = vision.robot_follow() #Default frame size width=640
#functions
dog_1.direction(rx) # Take as input the x position from a get_pos() function and return directions 2 for Go Right, 1 for Go Left,-1 for No detection and 0 for StayThat class used to return direction to the robot about the distance from the target eg. face
dog_1 = vision.robot_follow() #Default frame size width=640
#functions
dog_1.direction(rx) # Take as input the x size from a get_rect() function and return directions 1 for Forward, 2 for Back,-1 for No detection and 0 for StayThat class uses the camera to track a black line on the floor.
line_follow = vision.line_follower() # Dedault parameters width=640,height=480,w=160,h=60 image width,heigh and area of detection on the center of the image
#functions
line_follow.detect_line(frame)# Take as input a image detects and marks the line and return a new image with the line marked
line_follow.get_pos() # Return the center of the line in the imageThat class used to control a buzzer with PWM.
buz_1 = control.buzzer(pin=25) # User selected pin with default frequency 1500Hz and DC 50%
#or
buz_1 = control.buzzer(pin=25,freq=1500,dc=50) # User selected pin, frequency and DC
#functions
buz_1.beep() # Short tone
buz_1.timer(count=10) # User selected time to delay with one short tone per secondThat function used to save the measurements from the data_logger() class to csv.
control.make_csv(data_list,filename="data.csv"That function returns the ip address of Wi-Fi network.
control.get_ip