whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.2k stars 221 forks source link

stepper.attach message "call gpio_install_isr_service() first" #376

Closed ar055 closed 3 years ago

ar055 commented 3 years ago

motor.stepper = stepper.attach(motor.dir_pin, motor.step_pin, motor.stpu, motor.min_spd, motor.max_spd, motor.max_acc, motor_max_jerk) E (30595) gpio: gpio_isr_handler_add(365): GPIO isr service is not installed, call gpio_install_isr_service() first

Does not affect the work.

ar055 commented 3 years ago

I check build 1603898213 commit b524cdb84c111f8e612e73a823142178a33753e3 board type ESP32-PICO-KIT

stepper.stopasync(motor.stepper) - it doesn't work for me, all stepper motors stop after stop steppers - motor.stepper:getposition() always 0 stepper.start(motor.stepper) does not continue moving

ar055 commented 3 years ago

My full dirty code for tests

DEBUG = 1
print("b.lua started")

function printf_d(...)
 if DEBUG==1 then
  print(string.format(...))
 end
end

printf_d("test %d",1000)

motor = {}

function motor:new(stpu, max_spd, min_spd, max_acc, max_jerk)
  if not max_jerk then
      print("Ussage motor:new(stpu, max_spd, min_spd, max_acc, max_jerk)")
  end
   newObj = {
    pos = 0,
    speed = 2000,
    accel = 150,
    jerk =100,
    stpu = stpu or 200,
    min_spd  = min_spd or 65,
    max_spd  = max_spd or 4500,
  }
   self.__index = self
   return setmetatable(newObj, self)
end

function motor:init(name, step_pin, dir_pin, en_pin)
  self.name = name or self.name
  self.step_pin = step_pin
  self.dir_pin = dir_pin
  self.en_pin = en_pin
  pio.pin.setdir(pio.OUTPUT,self.step_pin, self.dir_pin, self.en_pin)
  self.stepper = stepper.attach(self.dir_pin, self.step_pin, self.stpu, self.min_spd, self.max_spd, self.accel, self.jerk)
  if DEBUG then
    print("----------------------------------")
    print("motor:init() name |"..self.name)
    print("----------------------------------")
    print("step_pin          |"..self.step_pin)
    print("dir_pin           |"..self.dir_pin)
    print("max_spd           |"..self.max_spd)
  end
end

function motor:setpos(pos, speed, accel, jerk)
  self.speed = speed or self.speed
  self.accel = accel or self.accel
  self.jerk  = jerk  or self.jerk 
  local distance = pos-self.pos
  nvs.write(self.name, "pos", self.pos) -- store old position
  nvs.write(self.name, "dis", distance)
  self.stepper:move(distance, self.speed, self.accel, self.jerk)
  self.pos = pos

  if DEBUG then
    if self.stepper:getdistance()~=0 then
      print("------------------------------")
      print("|motor:setpos() name ", self.name) 
      print("------------------------------")

      print("|dist   |\t", distance) 
      print("|speed  |\t", self.speed) 
      print("|accel  |\t", self.accel) 
      print("|jerk   |\t", self.jerk)
      print("------------------------------\n")
    end
  end
end

function motor_run(...)
  arg = {...}
  t = {}

  for k,v in pairs(arg) do
    if (v.stepper:getdistance() ~=0) then
      table.insert(t, v.stepper) 
      pio.pin.setlow(v.en_pin)        
    end
  end

  stepper.start(t)

  for k,v in pairs(arg) do
    pio.pin.sethigh(arg[k].en_pin)
  end
end

function run()
    motor_run(a,b,c)
end

function home()
 a:setpos(0)
 b:setpos(0)
 c:setpos(0)
 thread.start(run)
end

if not a then
local stp = 200*15.4*32*1.8/360

--  a = motor:new(200*13.7344*32*1.8/360, 4500, 65, 150, 100)
  a = motor:new(stp, 4500, 65, 150, 100)
  a:init("a",12, 13, 15) -- step, dir, en
end

if not b then
  b = motor:new(200*32*1.8/8, 4500, 65, 100, 100)
  b:init("b",27, 14, 15)
end

if not c then
  c = motor:new(200*32*1.8/8, 4500, 65, 150, 100)
  c:init("c",25, 26, 15)
end

--print("\nheap: "..collectgarbage("count"))
--collectgarbage("collect")
--print("heap: "..collectgarbage("count"))

--------------------------------------test
function pos_read()
  a_pos = nvs.read(a.name,"pos")
  a_dis = nvs.read(a.name,"dis")
  b_pos = nvs.read(b.name,"pos")
  b_dis = nvs.read(b.name,"dis")

  print("nvs a pos: "..a_pos, "nvs a dis: "..a_dis,"stepper a dis: ".. a.stepper:getdistance())
  print("nvs abpos: "..b_pos, "nvs b dis: "..b_dis,"stepper b dis: ".. b.stepper:getdistance())
end

a:setpos(180,300)
b:setpos(50,200)

thread.start(run)
tmr.sleepms(2000)
---------------------------------------------
print("stepper.stopasync(b.stepper)")
stepper.stopasync(b.stepper)
--stepper.stop(b.stepper)
pos_read()

tmr.sleepms(4000)
-------------------------------------------
print("stepper.stopasync(a.stepper)")
stepper.stopasync(a.stepper)
--stepper.stop(a.stepper)
pos_read()
--stepper.start(a.stepper)
print("b.lua ended")
ar055 commented 3 years ago

I also noticed that only 4 motors can work.

a:setpos(20); b:setpos(20); c:setpos(20); d:setpos(20); e:setpos(20)
run()

or easy

e:setpos(20)
run()

stepper e does not move.

my steppers config:

  a = motor:new(200*15.4*32*1.8/360, 4500, 65, 150, 100)
  a:init("a",12, 13, 15) -- step, dir, en

  b = motor:new(200*32*1.8/8, 4500, 65, 100, 100)
  b:init("b",27, 14, 15)

  c = motor:new(200*32*1.8/8, 4500, 65, 150, 100)
  c:init("c",19, 23, 15)

  d = motor:new(200*32*1.8/8, 4500, 65, 150, 100)
  d:init("d",21, 22, 15)

  e = motor:new(200*32*1.8/8, 4500, 65, 150, 100)
  e:init("e",25, 26, 15)

I change pins a <-->e, same result

ar055 commented 3 years ago

Excellent! It works.