Submarine Drone

View previous topic View next topic Go down

Submarine Drone

Post by MrSparks on Thu Feb 16, 2012 1:13 am

I've spent too long trying to get this working. I feel like I'm missing something glaringly obvious. I think I just need someone else to look at it and go "ya, you forgot to plug this in" or something.
Here it is:
Code:
// [RCD]
Val
{
   HTRM(default=0, min=-10, max=10)
   PITCH(default=0, min=-3, max=3)
   SPN(default=0, max=5000)
   VTRM(default=0, min=-10, max=10)
   YAW(default=0, min=-3, max=3)
}
Key
{
}
Body
{
   Core() {
      S:Chip(name=htr) {
         S:Arm(angle=VTRM) { }
         N:Frame(angle=-150, option=1) {
            N:Wheel(angle=-120, power=SPN, brake=1000) {
               N:Frame(angle=-30) {
                  N:Weight(angle=-30) {
                     E:Weight() { }
                     W:Weight() { }
                  }
                  N:Weight(angle=90) {
                     E:Weight() { }
                     W:Weight() { }
                  }
               }
            }
         }
      }
      S:Trim(angle=90, name=vtr) {
         N:Chip() { }
         S:Arm(angle=HTRM) { }
      }
   }
}
Lua
{math.sgn = function (x) if x < 0 then return -1 elseif x == 0 then return 0 else return 1 end end

function starter()
   vrot=0
   hrot=0
end

function OnInit()
   starter()   
end

function OnReset()
   starter()
end

function OnFrame()
   SPN=_KEY(4)*5000
   vrot=math.cos(_EZ(vtr))
   hrot=math.cos(_EZ(htr))
   PITCH=PITCH+4*(_KEY(0)-_KEY(1))-2*math.sgn(PITCH)
   YAW=YAW+4*(_KEY(2)-_KEY(3))-2*math.sgn(YAW)
   HTRM=vrot*YAW+hrot*PITCH
   VTRM=hrot*YAW+vrot*PITCH
end}


Last edited by MrSparks on Fri Feb 17, 2012 6:11 pm; edited 1 time in total (Reason for editing : Found first problem.)

MrSparks
Plane
Plane

Posts: 38
Join date: 2012-01-05
Age: 22
Location: Michigan

View user profile

Back to top Go down

Re: Submarine Drone

Post by MrSparks on Fri Feb 17, 2012 6:20 pm

Does _EZ() not pay attention to what chip it's supposed to be reporting on?
I mean, that's the only thing I can think of that could explain why the 2 tail fins don't move independently.

MrSparks
Plane
Plane

Posts: 38
Join date: 2012-01-05
Age: 22
Location: Michigan

View user profile

Back to top Go down

Re: Submarine Drone

Post by DanielLC on Mon Feb 20, 2012 3:08 am

Everything but the Lua code is capitalized before the program is run. Normally, that means that you don't have to worry about capitalization. Unfortunately, it also means that every variable named outside of the Lua must be capitalized in the Lua.

Make sure all the variables used outside Lua are all caps.

Short version: Change vtr to VTR and htr to HTR.

Code:
// [RCD]
Val
{
  HTRM(default=0, min=-10, max=10)
  PITCH(default=0, min=-3, max=3)
  SPN(default=0, max=5000)
  VTRM(default=0, min=-10, max=10)
  YAW(default=0, min=-3, max=3)
}
Key
{
}
Body
{
  Core() {
      S:Chip(name=HTR) {
        S:Arm(angle=VTRM) { }
        N:Frame(angle=-150, option=1) {
            N:Wheel(angle=-120, power=SPN, brake=1000) {
              N:Frame(angle=-30) {
                  N:Weight(angle=-30) {
                    E:Weight() { }
                    W:Weight() { }
                  }
                  N:Weight(angle=90) {
                    E:Weight() { }
                    W:Weight() { }
                  }
              }
            }
        }
      }
      S:Trim(angle=90, name=VTR) {
        N:Chip() { }
        S:Arm(angle=HTRM) { }
      }
  }
}
Lua
{math.sgn = function (x) if x < 0 then return -1 elseif x == 0 then return 0 else return 1 end end

function starter()
  vrot=0
  hrot=0
end

function OnInit()
  starter() 
end

function OnReset()
  starter()
end

function OnFrame()
  SPN=_KEY(4)*5000
  vrot=math.cos(_EZ(VTR))
  hrot=math.cos(_EZ(HTR))
  PITCH=PITCH+4*(_KEY(0)-_KEY(1))-2*math.sgn(PITCH)
  YAW=YAW+4*(_KEY(2)-_KEY(3))-2*math.sgn(YAW)
  HTRM=vrot*YAW+hrot*PITCH
  VTRM=hrot*YAW+vrot*PITCH
end}

DanielLC
Tank
Tank

Posts: 68
Join date: 2010-10-24

View user profile

Back to top Go down

Re: Submarine Drone

Post by MrSparks on Mon Feb 20, 2012 12:45 pm

DanielLC wrote:Everything but the Lua code is capitalized before the program is run. Normally, that means that you don't have to worry about capitalization. Unfortunately, it also means that every variable named outside of the Lua must be capitalized in the Lua.

Make sure all the variables used outside Lua are all caps.

Short version: Change vtr to VTR and htr to HTR.


Not in your post but possibly implied: Chip names are variables?

Either way, that doesn't fix it. Yes it does, I forgot to set the Lua

MrSparks
Plane
Plane

Posts: 38
Join date: 2012-01-05
Age: 22
Location: Michigan

View user profile

Back to top Go down

Re: Submarine Drone

Post by DanielLC on Mon Feb 20, 2012 7:36 pm

Not in your post but possibly implied: Chip names are variables?


Yes. It's the chip number. For example, 0 is the base chip.

I figured out your problem when I had it print out these numbers. It gave 'nil' for both of them.

DanielLC
Tank
Tank

Posts: 68
Join date: 2010-10-24

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum