local SLEEP = 0.1
local robot = component.proxy(component.list("robot")())
local sides = {back = 2,front = 3,down = 0,up = 1}
local waitCharge = false

local function energyCheck()
  local percent = computer.energy() / computer.maxEnergy()
  if percent > 0.9 then
      waitCharge = false
      return true
    elseif percent > 0.3 then
        return not waitCharge
    end
  waitCharge = true
  return false
end

local function main()
    if energyCheck() then
        robot.swing(sides.front)
    end
    computer.pullSignal(SLEEP)
end

while true do pcall(main) end
