Hello,
I’ve been working on the GoPiGo lately, and I came across a behavior I don’t understand.
I am trying to make the robot rotate as precisely as possible, as I want it to rotate 90 degrees all the time. I am using the compass to get a precise angle (if possible less than 5° error). I am slowing down the robot while it is rotating, otherwise it will overshoot its target angle.
The thing is that sometimes one of the motor, generally the left one, does not turn back to maximum speed after a rotation, thus making it turn instead of driving forwards. Any idea why this is happening?
I am using this code for the rotation for the moment:
def turn90DRight(self):
-gopigo.set_speed(self.TURNSPEED)
-time.sleep(0.1)
-self.compass.update()
-start=self.compass.headingDegrees
-target= (start+90)%360
-gopigo.right_rot()
-while True:
–self.compass.update()
–time.sleep(0.1)
–current=self.compass.headingDegrees
–if math.fabs(current - target) < 5:
—gopigo.stop()
—time.sleep(0.1)
—gopigo.set_speed(self.FORWARDSPEED)
—break
and this code to drive forwards:
def goForward(self):
-if self.sideFollowed == WallFollowed.Right:
–gopigo.servo(self.RIGHTSERVOANGLE)
-else:
–gopigo.servo(self.LEFTSERVOANGLE)
-time.sleep(0.1)
-self.isTurnPossible = True
-gopigo.enc_tgt(1,1,29)
-time.sleep(0.1)
-gopigo.fwd()
-time.sleep(0.1)
-while gopigo.read_status()[0] == 1:
–if gopigo.us_dist(15) < self.ROBOTLENGTH*3:
–self.isTurnPossible = False
I am also having overshooting problem because the compass doesn’t seem to update fast enough.
Edit: the “-” is the indentation, I can’t seem to find a way to make it show on my post