Skip to content

Commit 0cadf12

Browse files
committed
fix 4.1 bugs
1 parent e6b0ffb commit 0cadf12

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

coderbot.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@
3535
"ctrl_hud_image":"",
3636
"load_at_start":"",
3737
"sound_start":"$startup.wav",
38-
"encoder":"True",
38+
"hw_version":"5",
3939
"audio_volume_level":"100",
4040
"wifi_mode":"ap",
4141
"wifi_ssid":"",
4242
"coderbot_CHANGEMEATFIRSTRUN":"coderbot",
4343
"packages_installed":"",
44-
"admin_password":""
44+
"admin_password":"",
45+
"hardware_version":"5"
4546
}

coderbot.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class GPIO_CODERBOT_V_4():
5454
PIN_ENCODER_RIGHT_A = 15
5555
PIN_ENCODER_RIGHT_B = 12
5656

57+
HAS_ENCODER = False
58+
5759
class GPIO_CODERBOT_V_5():
5860
# motors
5961
PIN_MOTOR_ENABLE = None #22
@@ -82,29 +84,36 @@ class GPIO_CODERBOT_V_5():
8284
PIN_ENCODER_RIGHT_A = 24 #15
8385
PIN_ENCODER_RIGHT_B = 25 #12
8486

87+
HAS_ENCODER = True
88+
8589
# PWM
8690
PWM_FREQUENCY = 100 #Hz
8791
PWM_RANGE = 100 #0-100
8892

93+
HW_VERSIONS = {
94+
"4": GPIO_CODERBOT_V_4(),
95+
"5": GPIO_CODERBOT_V_5()
96+
}
97+
8998
class CoderBot(object):
9099

91100
# pylint: disable=too-many-instance-attributes
92101

93-
def __init__(self, motor_trim_factor=1.0, encoder=True):
102+
def __init__(self, motor_trim_factor=1.0, hw_version="5"):
94103
try:
95104
self._mpu = mpu.AccelGyroMag()
96105
logging.info("MPU available")
97106
except:
98107
logging.info("MPU not available")
99108

100-
self.GPIOS = GPIO_CODERBOT_V_5()
109+
self.GPIOS = HW_VERSIONS.get(hw_version, GPIO_CODERBOT_V_5())
101110
self._pin_out = [self.GPIOS.PIN_LEFT_FORWARD, self.GPIOS.PIN_RIGHT_FORWARD, self.GPIOS.PIN_LEFT_BACKWARD, self.GPIOS.PIN_RIGHT_BACKWARD, self.GPIOS.PIN_SERVO_1, self.GPIOS.PIN_SERVO_2]
102111
self.pi = pigpio.pi('localhost')
103112
self.pi.set_mode(self.GPIOS.PIN_PUSHBUTTON, pigpio.INPUT)
104113
self._cb = dict()
105114
self._cb_last_tick = dict()
106115
self._cb_elapse = dict()
107-
self._encoder = encoder
116+
self._encoder = self.GPIOS.HAS_ENCODER
108117
self._motor_trim_factor = motor_trim_factor
109118
self._twin_motors_enc = WheelsAxel(
110119
self.pi,

data/defaults/config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@
3535
"ctrl_hud_image":"",
3636
"load_at_start":"",
3737
"sound_start":"$startup.wav",
38-
"encoder":"True",
38+
"hw_version":"5",
3939
"audio_volume_level":"100",
4040
"wifi_mode":"ap",
4141
"wifi_ssid":"",
4242
"coderbot_CHANGEMEATFIRSTRUN":"coderbot",
4343
"packages_installed":"",
44-
"admin_password":""
44+
"admin_password":"",
45+
"hardware_version": "5"
4546
}

main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,11 @@ def remove_doreset_file():
461461
pass
462462

463463
def align_wifi_config():
464-
out = os.popen("sudo ./wifi.py getcfg --ssid").read()
465-
if "coderbot_" in out:
466-
app.bot_config["wifi_ssid"] = out.split()[0]
467-
Config.write(app.bot_config)
468-
app.bot_config = Config.get()
464+
out = os.popen("sudo ./wifi.py getcfg --ssid").read()
465+
if "coderbot_" in out:
466+
app.bot_config["wifi_ssid"] = out.split()[0]
467+
Config.write(app.bot_config)
468+
app.bot_config = Config.get()
469469

470470
# Finally, get the server running
471471
def run_server():
@@ -476,7 +476,7 @@ def run_server():
476476
app.bot_config = Config.read()
477477
align_wifi_config()
478478
bot = CoderBot.get_instance(motor_trim_factor=float(app.bot_config.get('move_motor_trim', 1.0)),
479-
encoder=bool(app.bot_config.get('encoder')))
479+
encoder=bool(app.bot_config.get('encoder')), encoder=bool(app.bot_config.get('encoder')))
480480
audio = Audio.get_instance()
481481
audio.say(app.bot_config.get("sound_start"))
482482

0 commit comments

Comments
 (0)