BGA
Second Officer
Offline
|
To try to answer your question in a clearer way, here is an example of a program that can locate, center and fire upon a recognized vision marker. It is a fully working example and it took ore time to comment it than to actually write it (although this is a bit of cheating as it is mostly a simplified version of the Seek & Destroy example. Still, it is a very small program that does something interesting).
def start():
// Create PID controllers for yaw and pitch angles.
pid_Pitch = rm_ctrl.PIDCtrl()
pid_Yaw = rm_ctrl.PIDCtrl()
// Marker position in the S1 field of view.
variable_X = 0
variable_Y = 0
// Maximum error that results in firing.
variable_Post = 0.01
// Move chassis and gimbal independently.
robot_ctrl.set_mode(rm_define.robot_mode_free)
// Enable vision marker detection.
vision_ctrl.enable_detection(rm_define.vision_detection_marker)
// Set PID parameters. Our controller uses mostly P and a bit of D.
pid_Yam.set_ctrl_params(115, 0, 5)
pit_Pitch.set_ctrl_params(85, 0, 3)
// Set fire count to 1 bead per firing.
gun_ctrl.set_fire_count(1)
while True:
// Try to find a marker.
list_MarkersList = RmList(vision_ctrl.get_marker_detection_info())
if list_MarkerList[1] == 1:
// Found exactly one marker. Get its X and Y positions.
variable_X = list_MarkerList[3]
variable_Y = list_MarkerList[4]
// Compute error (offset) from center of view for yaw and pitch axes.
pid_Yaw.set_error(variable_X - 0.5)
pid_Pitch.set_error(0.5 - variable_Y)
// Rotate the gimbal to point to the center of the identified marker.
gimbal_ctrl.rotate_with_speed(pid_Yaw.get_output(), pid_Pitch.get_output())
// Wait a bit to stabilize.
time.sleep(0.05)
if abs(variable_X - 0.5) <= variable_Post and abs(0.5 - variable_Y) <= variable_Post:
// Error is smaller than or equal to our limit. Fire!
gun_ctrl.fire_once()
// Make sure we do not fire more than once per second.
time.sleep(1)
else:
// Marker not found or multiple markers found. Make sure we stop rotating.
gimbal_ctrl.rotate_with_speed(0, 0)
|
|