RigidChips
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Submarine Drone

2 posters

Go down

Submarine Drone Empty Submarine Drone

Post by MrSparks Wed Feb 15, 2012 6:13 pm

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 11:11 am; edited 1 time in total (Reason for editing : Found first problem.)

MrSparks
Tank
Tank

Posts : 73
Join date : 2012-01-05
Age : 33
Location : Michigan

Back to top Go down

Submarine Drone Empty Re: Submarine Drone

Post by MrSparks Fri Feb 17, 2012 11:20 am

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
Tank
Tank

Posts : 73
Join date : 2012-01-05
Age : 33
Location : Michigan

Back to top Go down

Submarine Drone Empty Re: Submarine Drone

Post by DanielLC Sun Feb 19, 2012 8:08 pm

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 : 78
Join date : 2010-10-23

Back to top Go down

Submarine Drone Empty Re: Submarine Drone

Post by MrSparks Mon Feb 20, 2012 5:45 am

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
Tank
Tank

Posts : 73
Join date : 2012-01-05
Age : 33
Location : Michigan

Back to top Go down

Submarine Drone Empty Re: Submarine Drone

Post by DanielLC Mon Feb 20, 2012 12: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 : 78
Join date : 2010-10-23

Back to top Go down

Submarine Drone Empty Re: Submarine Drone

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

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