I updated index.html to enable the second joystick and updated robot_controller.py
def init( self ):
global servo_pos
gopigo.set_speed(200)
gopigo.stop()
#gopigo.fwd()
gopigo.servo(100)
self.lastServoSettingsSendTime = 0.0
self.lastUpdateTime = 0.0
self.lastMotionCommandTime = time.time()
self.servo_pos=100
and
def setNeckJoystickPos( self, joystickX, joystickY ):
#print ("g")
joystickX, joystickY = self.normaliseJoystickData( joystickX, joystickY )
if debug:
print ("Right joy",joystickX, joystickY)
#print (self.speed_r*joystickY)
#gopigo.set_right_speed(int(self.speed_r*joystickY))
#gopigo.fwd()
#self.lastMotionCommandTime = time.time()
if joystickX > .5:
self.servo_pos += 1
if self.servo_pos > 180:
self.servo_pos = 180
print ("Servo Left by 1 at ",self.servo_pos)
gopigo.servo(self.servo_pos)
elif joystickX <-.5:
self.servo_pos -= 1
if self.servo_pos < 0:
self.serv_pos = 0
print ("Servo Right by 1 at ",self.servo_pos)
gopigo.servo(self.servo_pos)
#else:
# print ("Servo Home")
# gopigo.servo(90)
My idea is to protect that the servo never goes below 0 and above 180.
For some reason I still get it in negative numbers…don’t understand why.
Servo Right by 1 at 0
Servo Right by 1 at -1
Servo Right by 1 at -2
Servo Right by 1 at -3
Servo Right by 1 at -4
Servo Right by 1 at -5
Servo Right by 1 at -6
Servo Right by 1 at -7
Above 180 it works great. Just below zero seems the if does not work.
Any input would be appreciated.
Thanks!
/Peshko