The latest mystery...
Our team wrote a method that commands a robot to move to a certain distance from an object based on a value of an I2C distance sensor (Rev2m). This routine varies the motors power proportionally to the distance and then finally stops the motors by setting their powers to 0. This routine is then called from runOpMode on a LinearOpMode object followed by a call to LinearOpMode.sleep(1000). Here is some pseudo code:
void moveToDistance() {
while (sensor.getDistance() > target) {
setMotorPower(max(sensor.getDistance()-target)*p, MIN_MOTOR_SPEED)
RobotLog.d (details...)
}
setMotorPower(0)
RobotLog.d ("done...")
}
void runOpMode () {
<initialize...>
moveToDistance();
sleep(1000);
<do some other stuff>
Mostly, this works fine. BUT, sometimes, the motors stay on for a significant period of time AFTER they have been commanded to 0.
In a log from a documented failure (below), we can see that the elapsed time from the initial call to moveToDistance() was around 300 msecs. In the log we can also see falling readings from the distance sensor and the log entry after the motors have been commanded to zero. We can also see the next operation starting after the 1 second pause.
And yet, on the video we captured, the robot trundles forward for what appears to be about another second before it moves on to its next movement.
So what is happening here? Is the call to sleep() somehow interfering with the USB communication queue? Are the high frequency calls to the I2C distance sensor overwhelming the communication manager in the hub (notice the 3 identical readings in a row in the log...not something we typically see, even at these very fast cycle times)? Something else?
Thanks in advance!
2020-01-16 18:08:57.881 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: Moving to Distance: 6.0Velocity: 1500.0
2020-01-16 18:08:57.901 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: Initial Distance Reading: 7.04724409448819
2020-01-16 18:08:57.902 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: preDriftTarget: 6.5slowThreshold: 11.0decelThreshold: 21.0slope: 115.0
2020-01-16 18:08:57.922 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:7.04724409448819 velocity: 350.0
2020-01-16 18:08:57.965 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.929133858267717 velocity: 350.0
2020-01-16 18:08:58.010 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.929133858267717 velocity: 350.0
2020-01-16 18:08:58.063 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.929133858267717 velocity: 350.0
2020-01-16 18:08:58.107 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.850393700787402 velocity: 350.0
2020-01-16 18:08:58.153 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.5748031496063 velocity: 350.0
2020-01-16 18:08:58.170 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: Finished Move to Distance
2020-01-16 18:08:59.170 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newRotateTo: Starting to rotate to 270.0
Our team wrote a method that commands a robot to move to a certain distance from an object based on a value of an I2C distance sensor (Rev2m). This routine varies the motors power proportionally to the distance and then finally stops the motors by setting their powers to 0. This routine is then called from runOpMode on a LinearOpMode object followed by a call to LinearOpMode.sleep(1000). Here is some pseudo code:
void moveToDistance() {
while (sensor.getDistance() > target) {
setMotorPower(max(sensor.getDistance()-target)*p, MIN_MOTOR_SPEED)
RobotLog.d (details...)
}
setMotorPower(0)
RobotLog.d ("done...")
}
void runOpMode () {
<initialize...>
moveToDistance();
sleep(1000);
<do some other stuff>
Mostly, this works fine. BUT, sometimes, the motors stay on for a significant period of time AFTER they have been commanded to 0.
In a log from a documented failure (below), we can see that the elapsed time from the initial call to moveToDistance() was around 300 msecs. In the log we can also see falling readings from the distance sensor and the log entry after the motors have been commanded to zero. We can also see the next operation starting after the 1 second pause.
And yet, on the video we captured, the robot trundles forward for what appears to be about another second before it moves on to its next movement.
So what is happening here? Is the call to sleep() somehow interfering with the USB communication queue? Are the high frequency calls to the I2C distance sensor overwhelming the communication manager in the hub (notice the 3 identical readings in a row in the log...not something we typically see, even at these very fast cycle times)? Something else?
Thanks in advance!
2020-01-16 18:08:57.881 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: Moving to Distance: 6.0Velocity: 1500.0
2020-01-16 18:08:57.901 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: Initial Distance Reading: 7.04724409448819
2020-01-16 18:08:57.902 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: preDriftTarget: 6.5slowThreshold: 11.0decelThreshold: 21.0slope: 115.0
2020-01-16 18:08:57.922 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:7.04724409448819 velocity: 350.0
2020-01-16 18:08:57.965 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.929133858267717 velocity: 350.0
2020-01-16 18:08:58.010 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.929133858267717 velocity: 350.0
2020-01-16 18:08:58.063 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.929133858267717 velocity: 350.0
2020-01-16 18:08:58.107 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.850393700787402 velocity: 350.0
2020-01-16 18:08:58.153 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: CRAWLING: Distance:6.5748031496063 velocity: 350.0
2020-01-16 18:08:58.170 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newMoveToDistance: Finished Move to Distance
2020-01-16 18:08:59.170 24490-24860/com.qualcomm.ftcrobotcontroller D/RobotCore: 14140LOG:newRotateTo: Starting to rotate to 270.0
Comment