FRC1076 / 2019-Competition

Code for 2019 Competition
2 stars 1 forks source link

Implement SonarSensor #48

Open mcolinj opened 5 years ago

mcolinj commented 5 years ago

Current stub implementation is in subsystems.remoteSensors.py

SonarSensor should create a communication channel to the sonar processor and listen for range updates about every 5 robot cycles. A receiveRangeUpdates() method should be called in the robot loop to receive the update, parse the payload, and save the range value to be returned to the PIDController on demand. The latest range update value is cached in the SonarSensor object so it can be returned to the PID Controller using it via the getPid() method.

This needs a crash free creation of the communication channel to the sonar unit. It should be robust enough to not fail if that doesn't work right away. As long as the channel is not successfully initialized, it should keep trying it every time receiveRangeUpdatesis called. e.g. if self.channel is None. So, it should squirrel away all of the values necessary to retry creating the channel.

mcolinj commented 5 years ago

You should be able to create this in the context of some unit test framework. Check with @EPrograming or @WilliamBallbach if you want help creating a unit test that talks both ends of a communication channel.

mcolinj commented 5 years ago

SonarSensor has to be the source of data for the PIDController, so it must identify itself as providing a displacement (rather than a rate). Be sure to add this method to it.

def getPIDSourceType(self): "Tell PID that sonar provides range not speed" return wpilib.interfaces.pidsource.PIDSource.PIDSourceType.kDisplacement