Esempio n. 1
0
        t = grantedtime

        for j in range(0, end_count):

            # Model the physics of the battery charging. This happens
            #   every time step whether a message comes in or not
            addenergy = charge_rate[(EVlist[j] - 1)] * (update_interval / 3600)
            currentsoc[j] = currentsoc[j] + addenergy / batt_size
            logger.debug(f'Added energy {addenergy} to EV at terminal {j}'
                         f' bringing it to SOC {currentsoc[j]}')

            # Check for messages from EV Controller
            endpoint_name = h.helicsEndpointGetName(endid[j])
            if h.helicsEndpointHasMessage(endid[j]):
                msg = h.helicsEndpointGetMessageObject(endid[j])
                instructions = h.helicsMessageGetString(msg)
                logger.debug(f'Received message at endpoint {endpoint_name}'
                             f' at time {t}'
                             f' with command {instructions}')

                # Update charging state based on message from controller
                # The protocol used by the EV and the EV Controller is simple:
                #       EV Controller sends "1" - keep charging
                #       EV Controller sends andything else: stop charging
                # The default state is charging (1) so we only need to
                #   do something if the controller says to stop
                if int(instructions) == 0:
                    # Stop charing this EV and move another one into the
                    #   charging station
                    _, _, _, newEVtype = get_new_EV(1)
Esempio n. 2
0
    instructions = []
    # for t in range(0, total_interval, update_interval): #

    # the EV sent its first message at 15min
    # start the controller at 15min + 7.5min
    grantedtime = h.helicsFederateRequestTime(fed, 22.5 * 60)
    # print('EV time: ',grantedtime/3600)

    t = grantedtime
    while t < total_interval:

        for j in range(0, len(enddest_EVsoc)):
            # 1. Receive SOC
            # print('endpt name: ',h.helicsEndpointGetName(end_EVsoc[j]))
            if h.helicsEndpointHasMessage(end_EVsoc[j]):
                msg = h.helicsEndpointGetMessageObject(end_EVsoc[j])
                currentsoc = h.helicsMessageGetString(msg)
                # print('currentsoc: ',currentsoc)
                # 2. Send instructions
                # destination_name = str(h.helicsEndpointGetDefaultDestination(end_EVsoc[j]))
                print(t / 3600, currentsoc)
                if float(currentsoc) <= 0.9:
                    instructions = 1
                else:
                    instructions = 0
                message = str(instructions)
                h.helicsEndpointSendMessageRaw(end_EVsoc[j], "", message)  #
                # print('Sent instructions: {}'.format(instructions))
            else:
                print("NO MESSAGE RECEIVED AT TIME ", t / 3600)