View unanswered posts | View active topics It is currently Wed Jul 23, 2014 9:26 am






Reply to topic  [ 11 posts ] 
Edit postReport this postReply with quotePSP-Nx-v3 how do I 
Author Message
Rookie

Joined: Fri Dec 30, 2011 4:18 pm
Posts: 3
Post Edit postReport this postReply with quotePSP-Nx-v3 how do I
I would like to use the L1 button to turn on or off a motor. New to robotC. tried this program but nothing happens. any ideas? thanks

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Code:
#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Sensor, S1,     ,                    sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     motorA,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNone, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/************************************************************************/
/*                                                                      */
/* Program Name: PSP-Nx-demo.c                                       */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2008 by mindsensors.com                                */
/* Email: info (<at>) mindsensors (<dot>) com                           */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; version 3 of the License.              */
/* Read the license at: http://www.gnu.org/licenses/gpl.txt             */
/*                                                                      */
/************************************************************************/

const ubyte Addr = 0x02;
const tSensors SensorPort = S1;        // Connect PSPNX sensorto this port!!
#include "PSP-Nx-lib.c"

int nleft1 = 0;
int nRightButton = 0;
int nEnterButton = 0;
int nExitButton = 0;

//////////////////////////////////////////////////////////////////////////////
//
//      Display the  Gamepad buttons and joystick status  on Nxt screen
//
/////////////////////////////////////////////////////////////////////////////

task
main ()
{
  int powerA;
  int l1;


   psp currState;

  //
  // Note: program cannot be terminated if we hijack the 'exit' button. So there has to be an escape sequence
  //       that will return buttons to system control! We'll use a triple click
  //
  nNxtExitClicks = 3;                // Triple clicking EXIT button will terminate program
  //
  nI2CBytesReady[SensorPort] = 0;

  //SensorType[SensorPort] = sensorI2CCustom9V;        // or perhaps use 'Lowspeed_9V_Custom0'??
  SensorType[SensorPort] = sensorI2CMuxController;
  wait10Msec (100);

  nxtDisplayTextLine (0, "mindsensors.com");
  nxtDisplayTextLine (1, "PSP-NX");

  while ( true )
    {
      wait1Msec (5);

      PSP_ReadButtonState(SensorPort, Addr, currState);

      l1 = (int)currState.l1;



      /*
      * Determine power for each motor.
       * trying to take value from L1 and multiply by 20.  If value is 1, motor should move.
      */
      powerA = l1 * 20;


        motor[motorA] = powerA;


    nxtDisplayTextLine(1,"motorA: %d", powerA);


    }

  wait10Msec (100);

  StopAllTasks ();
}


Fri Dec 30, 2011 4:21 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
You can't really use a built-in driver and a custom driver on the same port, it often causes problems. I would advise you to connect the PSP-Nx to Port S2 and configure it as sensorI2CCustom9V (unless it's not a 9V sensor).

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Dec 31, 2011 5:39 am
Profile WWW
Rookie

Joined: Fri Dec 30, 2011 4:18 pm
Posts: 3
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
Hey Miki,

that helps I now have the button recognized. so does the value of the button equal 1 when unpressed and 0 when pressed? if so how can I reverse that? thanks


Sun Jan 01, 2012 3:09 pm
Profile
Rookie

Joined: Sun Nov 16, 2008 3:07 pm
Posts: 45
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
mightor wrote:
You can't really use a built-in driver and a custom driver on the same port, it often causes problems. I would advise you to connect the PSP-Nx to Port S2 and configure it as sensorI2CCustom9V (unless it's not a 9V sensor).

- Xander


Hey Xander,

Followup on your advice. Do you mean that the program should not have:

#pragma config(Sensor, S1, , sensorI2CMuxController)

Our FTC team 1001 has found that line to cause the Hitechnic motor and servo controllers we have attached to S1 to not work and we didn't know what that line means nor where it comes from.

I apologize if I'm suffering from paranoia, but we really think it keeps "magically" reappearing. i.e. we delete it, then it comes back (usually at really bad times).

When we open the Motor and Sensor config dialog, it shows the expected things - just the Hitechnic/Tetrix motor hubs on S1 as in this simple example:
#pragma config(Hubs, S1, HTMotor, HTMotor, none, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Motor, motorA, spinny, tmotorNormal, openLoop)
#pragma config(Motor, motorB, FlippyL, tmotorNormal, openLoop)
#pragma config(Motor, motorC, FlippyR, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_1, motorRight, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorLeft, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C2_1, motorInOut, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C2_2, motorUpDown, tmotorNormal, openLoop)

This file has had a lot of kids typing things in it over the last few months, and maybe they did something goofy at some stage, but imho, this sensorI2CMuxController thing has a mysteriously zombie like quality.

Would you be so kind to clarify if you mean the second line of S1 pragmas should be whacked and shine any light you can on whether the motor and sensor setup gets "saved" anywhere other than in the #pragmas of the .c file?

Much appreciated.

Thanks,
David Fort
Mentor, FIRST FTC/FRC team 1001


Sun Jan 29, 2012 6:15 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
Hiya David,

What do you have on your tetrix controller tab?
Attachment:
Screenshot-2012-01-30_07.24.34.png
Screenshot-2012-01-30_07.24.34.png [ 14.66 KiB | Viewed 4158 times ]


Is that configured properly?

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 30, 2012 2:26 am
Profile WWW
Rookie

Joined: Sun Nov 16, 2008 3:07 pm
Posts: 45
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
I attached pictures of the Tetrix controller tab
Attachment:
File comment: Tetrix Controller Tab
RobotCMotorSensor.JPG
RobotCMotorSensor.JPG [ 69.73 KiB | Viewed 4138 times ]

and the sensor tab.
Attachment:
File comment: The Sensor tab
RobotCSensor.JPG
RobotCSensor.JPG [ 50.98 KiB | Viewed 4138 times ]

It all looks reasonable to me. But doesn't match the #pragma's I've got.


Mon Jan 30, 2012 10:40 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
Why not configure it like this:

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Sensor, S2,     PSPNX,          sensorI2CCustomFastSkipStates9V)
#pragma config(Motor,  motorA,          MOTA,          tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

const ubyte PSPNX_ADDR = 0x02;
#include "PSP-Nx-lib.c"

int nleft1 = 0;
int nRightButton = 0;
int nEnterButton = 0;
int nExitButton = 0;

//////////////////////////////////////////////////////////////////////////////
//
//      Display the  Gamepad buttons and joystick status  on Nxt screen
//
/////////////////////////////////////////////////////////////////////////////

task main ()
{
  int powerA;
  int l1;

  psp currState;

  //
  // Note: program cannot be terminated if we hijack the 'exit' button. So there has to be an escape sequence
  //       that will return buttons to system control! We'll use a triple click
  //
  nNxtExitClicks = 3;                // Triple clicking EXIT button will terminate program
  //
  nI2CBytesReady[PSPNX] = 0;

  nxtDisplayTextLine (0, "mindsensors.com");
  nxtDisplayTextLine (1, "PSP-NX");

  while ( true )
  {
    wait1Msec (5);
    PSP_ReadButtonState(PSPNX, PSPNX_ADDR, currState);
    l1 = (int)currState.l1;
   
    /*
    * Determine power for each motor.
    * trying to take value from L1 and multiply by 20.  If value is 1, motor should move.
    */
    powerA = l1 * 20;
    motor[MOTA] = powerA;
    nxtDisplayTextLine(1,"motorA: %d", powerA);
  }
  wait10Msec (100);
}


Use the motor and sensor configuration tool to set your sensor types, don't mix doing it with code and doing it with this tool. It will only lead to a giant mess. The PSPNX is now configured to be connected to S2. Change the setup with the utility to make it work with another port. Also consider giving port names sensible names, like PSPNX instead of "SensorPort". I know this is straight from the Mindsensors example, but they're only really good for showing you how to do something quickly.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Jan 31, 2012 1:16 am
Profile WWW
Rookie

Joined: Sun Nov 16, 2008 3:07 pm
Posts: 45
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
Assuming that the root of our problems came from deleting #pragmas in the text editor instead of using the Motor & Sensor setup dialog, Is there a way to get them back in synch - for example, are the contents of the Motor and Sensor setup dialog stored somewhere that we can go clean up so they match the #pragmas again?


Tue Jan 31, 2012 2:23 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
They are stored in the pragmas :) I would just remove the pragma lines and recreate them with the setup tool.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Jan 31, 2012 2:28 pm
Profile WWW
Rookie

Joined: Fri Mar 11, 2011 9:30 pm
Posts: 12
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
david fort wrote:
Assuming that the root of our problems came from deleting #pragmas in the text editor instead of using the Motor & Sensor setup dialog, Is there a way to get them back in synch - for example, are the contents of the Motor and Sensor setup dialog stored somewhere that we can go clean up so they match the #pragmas again?


Dave,

Could this issue -> viewtopic.php?f=1&t=4176 be inter-related? I recall us seeing something like you have described once or twice with an extra line in the pragmas showing up but haven't seen it lately and haven't tried to recreate it.

Our own experience with this stopping being a problem may have coincided with going to 4 controllers which might leave no room for a spurious entry to hang in memory. A thought, perhaps when the dialog reads the pragmas, it doesn't clean up memory for storing pragmas that it doesn't read or for getting ready to write pragmas that aren't currently in the UI. Could it be leaving something in memory if you're not exiting and reloading ROBOTC.

You might want to try a mix of deleting pragmas, saving, closing the ROBOTC environment, and then re-opening and re-adding the pragmas.

_________________
Jamie Diamond
Cougar Robotics Team (Ring It Up!, Bowled Over!, Get Over It! #4251)
(Smart Moves #127, Climate Connections #437, Power Puzzle #1470)
coach@cougarrobot.com
http://www.cougarrobot.com
https://www.facebook.com/CougarRoboticsTeam


Tue Jan 31, 2012 3:19 pm
Profile
Rookie

Joined: Sun Nov 16, 2008 3:07 pm
Posts: 45
Post Re: Edit postReport this postReply with quotePSP-Nx-v3 how d
Maybe it is a simple matter that if you have one of these extra pragmas, the gui doesn't remove it.

It is possible the kids used the Sensor Tab to set up something and messed it up, conflicting with the Motor and Servo setup from the Tetrix tab, but in my experience (just tested with 3.05) 'OK' on the Motor and Sensor setup rewrites the pragmas and removes the extra one.

In any case, I guess I've hijacked this thread long enough. I'll just delete the line and check for its presence regularly.


Sun Feb 05, 2012 9:04 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.