FRC1076 / RobotKitLib

Robotpy-WPILIB equivalent for raspberry pi robot kit
1 stars 1 forks source link

Create the UltraSonic component interface for use in the robot.py framework. #9

Open mcolinj opened 3 years ago

mcolinj commented 3 years ago

Look at the Freenove example code for a sonar unit, and move the function into a UltraSonic class so that it can be used. Refer to the wpilib UltraSonic interface so we can keep it compatible.

EmilyRobotics commented 3 years ago

Looks like the built in ultrasonic sensor class has three main functions: send_trigger_pulse() wait_for_echo get_distance

To make a wpilib-compatable version, you will have to: add a unit converter funciton, giving output in inches or mm create a new counter program similar in function to the combination of send_trigger_pulse and wait_for_echo and add the rest of the wpilib functions (should be pretty simple) to make it fully compatable

Might want to consider making a base sensor class, similar to the one wpilib has to make things easier when/if we get new sensors from electrical

see Ultrasonic.py in the freenove code, wpilib documentation, and [wpilib code](https://github.com/robotpy/robotpy-wpilib/blob/2019/wpilib/wpilib/ultrasonic.py

EmilyRobotics commented 3 years ago

Then for the camera motor, you should probably put that in its own seperate class

mcolinj commented 3 years ago

Camera motor should be an instance of the Servo class. There is probably a reason to combine the two servos into something like a tilt/pan object. But we don't have much control of the servos, and don't know where they are, so as an assembly, it would have limited capabilities.

mcolinj commented 3 years ago

This job might look intimidating at first, but you can work on it in stages.

  1. Look at the Freenove code and see how the Ultrasonic interface works. https://github.com/Freenove/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/tree/master/Code/Server

  2. Manually run it, maybe surround it with a loop that reports range values to convince yourself that it does work. You don't have to have the tilt/pan assembled for this. You can just plug in the sonar unit and set it on the robot platform or another holder. Or if you just have a Raspberry Pi and a sonar unit, you can wire them up for testing.

  3. Then think about how you could package it up so it looks more like the UltraSonic interface in wpilib.

sorenfnt commented 3 years ago

I hope someone else worked on this issue today, cause I sure didn't!

sorenfnt commented 3 years ago

https://github.com/Freenove/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/blob/master/Code/Server/Ultrasonic.py The link to the existing sensor code from Freenove

sorenfnt commented 3 years ago

It looks like the Freenove code handles getting the distance by sending 3 trigger pulses in quick succession and taking the middle value, a clever internal data smoothing. We may or may not want to adopt this either as data smoothing or in addition to computing a rolling average/throwing out bad values.