Example #1
0
 def __init__(self, **kwargs):
     super(Right, self).__init__(**kwargs)
     self.table = Time_Table(pos_hint={
         'x': 0,
         'y': 0.5
     },
                             size_hint=(1, 0.5))
     self.accel = Accel(pos_hint={
         'x': 0.6,
         'y': 0.25
     },
                        size_hint=(0.4, 0.25),
                        acc=[50, 50])
     self.add_widget(self.table)
     self.add_widget(self.accel)
     self.map = TrackMap(pos_hint={
         'x': 0.099,
         'y': 0.2482
     },
                         size_hint=(0.5, 0.25))
     self.add_widget(self.map)
     #for testing
     Clock.schedule_interval(self.acc_test, 0.2)
from time import sleep
#from datetime import datetime, timedelta

from accel import Accel
#from driver import Driver

accel = Accel()

while (True):
    data = accel.read_data()
    print("x-accel: " + str(data))
    sleep(0.2)
Example #3
0
def run_simulation(args):
    t_end = args.time
    dt = args.dt
    start_angle = 0.05

    accel = Accel((args.accel_stddev_x, args.accel_stddev_z), args.gravity)
    gyro = Gyro(args.gyro_stddev, args.gyro_biasdrift_stddev)
    filt = ComplementaryFilter(args.filter_acc_weight, args.gravity,
                               start_angle)

    accel_data = []
    gyro_data = []
    angles = []

    true_angle = start_angle
    true_angvel = 0.0

    ts = np.arange(0, t_end, dt)
    true_angles = true_angle * np.ones(shape=ts.shape)

    for i, t in enumerate(ts):
        acc_obs = accel.get(true_angles[i])
        angvel_obs = gyro.get(true_angvel, dt)

        accel_data.append(acc_obs)
        gyro_data.append(angvel_obs)

        ang_est = filt.get(acc_obs, angvel_obs, dt)

        angles.append(ang_est)

    angles = np.array(angles)

    angle_error = angles - true_angles
    mean_abs_error = np.mean(np.abs(angle_error))

    if not args.no_print:
        print("Mean abs error is %f radians (%f degrees)" %
              (mean_abs_error, np.degrees(mean_abs_error)))

    if not args.no_plot:
        import matplotlib.pyplot as plt

        plt.figure("Filter Results")
        plt.plot(ts, angles, label='Estimated')
        plt.plot(ts, true_angles, label='True')
        plt.xlabel('Time (s)')
        plt.ylabel('Angle (rad)')
        plt.title("Estimated vs. True Angle")
        plt.legend()

        plt.figure("Angle Error")
        plt.plot(ts, angle_error)
        plt.xlabel('Time (s)')
        plt.ylabel('Angle Error (rad)')
        plt.title("Angle Error")

        accel_data = np.array(accel_data)
        accel.plot(ts, accel_data)
        gyro_data = np.array(gyro_data)
        gyro.plot(ts, gyro_data)
        plt.show()

    return mean_abs_error
Example #4
0
#Accel-Test

from accel import Accel
import time, datetime

ac = Accel()
t1 = datetime.datetime.now()
a = ac.getResult(1)
t2 = datetime.datetime.now()
t = t2-t1
print(a)
print(t)
Example #5
0
    def __init__(self, **kwargs):
        super(Main, self).__init__(**kwargs)
        config = ConfigParser()
        config.read('config.ini')
        cfgs = config['sensor_values']

        #setting up widgets
        self.tire_temps = Tire_Temps(pos_hint={
            "center_x": 0.5,
            "y": 0
        },
                                     size_hint=(0.45, 0.25),
                                     temps=[[50, 50, 50, 50], [50, 50, 50, 50],
                                            [50, 50, 50, 50], [50, 50, 50,
                                                               50]],
                                     boundary=int(cfgs['infrared_offset']))
        self.battery = Parametric_Graph(pos_hint={
            "x": 0,
            "y": 0.38
        },
                                        size_hint=(0.25, 0.45),
                                        label='Voltage (V)',
                                        boundaries=[0, 10, 300, 588])
        self.kw = Parametric_Bar(pos_hint={
            "x": 0.02,
            "y": 0.85
        },
                                 size_hint=(0.05, 0.13),
                                 name="Power(kW)",
                                 value=0,
                                 max_value=int(cfgs['kw_max']),
                                 color=[0, 0, 1, 1],
                                 orientation="vertical")
        self.cur = Parametric_Bar(pos_hint={
            "x": 0.09,
            "y": 0.85
        },
                                  size_hint=(0.05, 0.13),
                                  name="Current(A)",
                                  value=0,
                                  max_value=int(cfgs['cur_max']),
                                  color=[0, 0, 1, 1],
                                  orientation="vertical")
        self.vol = Parametric_Bar(pos_hint={
            "x": 0.16,
            "y": 0.85
        },
                                  size_hint=(0.05, 0.13),
                                  name="Voltage(V)",
                                  value=0,
                                  max_value=int(cfgs['vol_max']),
                                  color=[0, 0, 1, 1],
                                  orientation="vertical")
        self.table = Time_Table(pos_hint={
            'x': 0.8,
            'y': 0.65
        },
                                size_hint=(0.2, 0.35))
        self.accel = Accel(pos_hint={
            'center_x': 0.5,
            'y': 0
        },
                           size_hint=(0.15, 0.25),
                           acc=[50, 50])
        #self.map = TrackMap(pos_hint = {'x':0.85, 'y':0.45}, size_hint = (0.18, 0.3))
        self.map = TrackMap2(size_hint=(None, None),
                             size=(Window.width * 0.3, Window.height * 0.5),
                             pos=(Window.width * 0.7, Window.height * 0.2))
        #pos_hint={'x': 0.75, 'y': 0.1}, size_hint=(0.2, 0.35)
        self.pc_status = Pc_Status(pos_hint={
            "x": 0.4,
            "y": 0.85
        },
                                   size_hint=(0.2, 0.15))
        self.apps = Parametric_Bar(pos_hint={
            "x": 0.35,
            "y": 0.65
        },
                                   size_hint=(0.05, 0.13),
                                   name="APPS(%)",
                                   value=0,
                                   max_value=int(cfgs['apps_max']),
                                   color=[0, 1, 0, 1],
                                   orientation="vertical")
        self.brake = Parametric_Bar(pos_hint={
            "x": 0.42,
            "y": 0.65
        },
                                    size_hint=(0.05, 0.13),
                                    name="Brake(%)",
                                    value=0,
                                    max_value=int(cfgs['brake_max']),
                                    color=[1, 0, 0, 1],
                                    orientation="vertical")
        self.bias = Brake_Bias(pos_hint={
            "x": 0.35,
            "y": 0.5
        },
                               size_hint=(0.1, 0.1),
                               percentage=0)
        self.rpmbar = RpmBar(pos_hint={
            "x": 0.35,
            "y": 0.8
        },
                             size_hint=(0.35, 0.05),
                             value=200,
                             max_value=int(cfgs['rpm_max']),
                             color=[1, 0, 0, 1])
        self.motor_temp = Icon_Indicator(pos_hint={
            "x": 0.3,
            "y": 0.35
        },
                                         size_hint=(0.1, 0.1),
                                         name="Motor Temp",
                                         value=0,
                                         unit="°C",
                                         boundaries=[
                                             int(cfgs['motor_temp_warn']),
                                             int(cfgs['motor_temp_crit'])
                                         ],
                                         source="assets/motor_icon.png",
                                         color=[1, 1, 1, 1],
                                         opacity=0.4)
        self.inv_temp = Icon_Indicator(pos_hint={
            "x": 0.4,
            "y": 0.35
        },
                                       size_hint=(0.1, 0.1),
                                       name="Inverter Temp",
                                       value=0,
                                       unit="°C",
                                       boundaries=[
                                           int(cfgs['inv_temp_warn']),
                                           int(cfgs['inv_temp_crit'])
                                       ],
                                       source="assets/inverter2.png",
                                       color=[1, 1, 1, 1],
                                       opacity=0.4)
        self.bat_temp = Icon_Indicator(pos_hint={
            "x": 0.5,
            "y": 0.35
        },
                                       size_hint=(0.1, 0.1),
                                       name="Battery Temp",
                                       value=0,
                                       unit="°C",
                                       boundaries=[
                                           int(cfgs['battery_temp_warn']),
                                           int(cfgs['battery_temp_crit'])
                                       ],
                                       source="assets/battery4.png",
                                       color=[1, 1, 1, 1],
                                       opacity=0.6)
        self.gps_speed = Parametric_Label(pos_hint={
            "x": 0.57,
            "y": 0.65
        },
                                          size_hint=(0.07, 0.1),
                                          name1="0",
                                          name2="GPS Speed",
                                          font1="32sp")
        self.hall_speed = Parametric_Label(pos_hint={
            "x": 0.635,
            "y": 0.65
        },
                                           size_hint=(0.07, 0.1),
                                           name1="0",
                                           name2="Sensor Speed",
                                           font1="32sp")
        self.dashboard = Dashboard(pos_hint={
            "x": 0.01,
            "y": 0.03
        },
                                   size_hint=(0.3, 0.33))
        self.drs_button = Drs_Button(pos_hint={
            "x": 0.5,
            "y": 0.65
        },
                                     size_hint=(0.05, 0.05))
        self.steering_wheel = Icon_Indicator(
            pos_hint={
                "x": 0.48,
                "y": 0.51
            },
            size_hint=(0.07, 0.07),
            name="Steering Angle",
            value=0,
            unit="°",
            boundaries=[100, 120],
            source="assets/steering_wheel2.png",
            color=[0.8, 0.8, 0.8, 1],
            angle=0,
            opacity=1)
        self.downforce = Icon_Indicator(pos_hint={
            "x": 0.6,
            "y": 0.35
        },
                                        size_hint=(0.1, 0.1),
                                        name="Downforce",
                                        value=0,
                                        color=[1, 1, 1, 1],
                                        opacity=0.9,
                                        source="assets/downforce_icon.png")
        self.enc_map = Parametric_Label(pos_hint={
            "x": 0.595,
            "y": 0.49
        },
                                        size_hint=(0.07, 0.1),
                                        name1="0",
                                        name2="Encoder Map",
                                        font1="32sp")

        #adding widgets
        self.add_widget(self.battery)
        self.add_widget(self.tire_temps)
        self.add_widget(self.kw)
        self.add_widget(self.cur)
        self.add_widget(self.vol)
        self.add_widget(self.table)
        self.add_widget(self.accel)
        self.add_widget(self.map)
        self.add_widget(self.pc_status)
        self.add_widget(self.apps)
        self.add_widget(self.brake)
        self.add_widget(self.bias)
        self.add_widget(self.rpmbar)
        self.add_widget(self.motor_temp)
        self.add_widget(self.inv_temp)
        self.add_widget(self.bat_temp)
        self.add_widget(self.gps_speed)
        self.add_widget(self.hall_speed)
        self.add_widget(self.dashboard)
        self.add_widget(self.drs_button)
        self.add_widget(self.steering_wheel)
        self.add_widget(self.downforce)
        self.add_widget(self.enc_map)

        #for testing
        self.bind(data=self.update)
#!/usr/bin/python

from accel import Accel
import time
from PID import PID


accelorometer = Accel()
accelorometer.wakeFromSleep()


startTimeForCalibration = time.time()
numReadings = 0
sumReadings= 0

while time.time() < (startTimeForCalibration+10.0):
    numReadings += 1
    sumReadings += accelorometer.getReadingX()


meanReading = 0 - (sumReadings / numReadings)




start_time = time.time()

# Set up the PID control system

pid = PID(P=1, I=1, D=1, Derivator=0, Integrator=0, Integrator_max=50, Integrator_min=-50)
Example #7
0
#!/usr/bin/python

from accel import Accel
from PID import PID
from motorPWM import MotorDriverHandler
import time

# train the accelorometer
startTimeForCalibration = time.time()
numReadings = 0
sumReadings= 0

trainingAccel = Accel(0)
trainingAccel.wakeFromSleep()

while time.time() < (startTimeForCalibration+4.0):
    sumReadings += trainingAccel.getReadingX()
    numReadings += 1


meanReading = 0 - (sumReadings / numReadings)

# Set up the accelorometer
accelorometer = Accel(meanReading)
accelorometer.wakeFromSleep()

# Set up the PID control system

pid = PID(P=3, I=0, D=0, Derivator=0, Integrator=0, Integrator_max=50, Integrator_min=-50)