|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Programming: MotorRcControl() vs GetRxInput()/SetServo()
Ok, I've been beating my head against this for a couple of days and haven't solved the problem. If I do the following, things work fine:
while(1) { // control motor connected to #8 with channel #3 MotorRcControl(1, 3, 8, 0); } ...but the following makes the servos connected to the uController go nuts: int armASpeed = 0; while(1) { // control motor connected to #8 with channel #3 armASpeed = GetRxInput(1, 3); PrintToScreen("armASpeed: %d", armASpeed); SetMotor(8, armASpeed); } Also, I see a value of 127 returned, no matter the position of the R/C stick. If I comment out the SetMotor() call I see the value of armASpeed change with the R/C stick position, as I would expect. So, it appears to be related to the SetMotor() call. I've checked the arguments against the UserAPI.h headers. Do I have a syntax problem? Is it timing? I don't trust this dual processor arrangement (it seems fragile) and I suspect it might be involved. Thanks, -Glenn |
|
#2
|
||||
|
||||
|
Re: Programming: MotorRcControl() vs GetRxInput()/SetServo()
An earlier search didn't turn up anything on SetMotor() or SetServo() but a second search turned up some examples using SetPWM(). I believe my problem has to do with the size of the variable I was using as an argument. Things seem to be working if I use:
unsigned char armASpeed = 0; while(1) { armASpeed = GetRxInput(1,3); PrintToScreen("armASpeed: %d\n",(int)armASpeed); SetPWM(8, armASpeed); } Thanks, -Glenn |
|
#3
|
||||
|
||||
|
Re: Programming: MotorRcControl() vs GetRxInput()/SetServo()
These commands look interesting. Are they available in EasyC 1.1 or are they from EasyC 2.0? I'm looking for a way to control the two motors in the SquareBot using channel 2 and 3 and then also control the servo using Channel 3 joystick with a side to side motion. The default system works this way, but when I use EasyC to combine autonomy with RC, this ability goes away. Any ideas would be appreciated.
EDIT: Silly me. The commands I was asking about are available in EasyC 1.1, you just have to choose Professional Level via the Options menu. Duh! Last edited by michael714 : 10-04-2006 at 18:59. |
|
#4
|
||||
|
||||
|
Re: Programming: MotorRcControl() vs GetRxInput()/SetServo()
Quote:
Code:
#include "UserAPI.h"
#define OUTPUT 0
#define INPUT 1
void IO_Initialization(void)
{
DefineControllerIO ( 4, INPUT ,INPUT ,INPUT ,INPUT ,INPUT ,INPUT ,INPUT ,INPUT ,INPUT ,INPUT ,OUTPUT ,INPUT ,OUTPUT ,OUTPUT ,OUTPUT ,OUTPUT ) ;
}
/**************************************************************************
* This code implements the behavior for controlling our 6 wheel robot with
* a articulated arm consisting of multiple parts. Each part will be
* referenced as armA, armB, etc.
**************************************************************************/
void main ( void )
{
// Connections to the controller
unsigned char uCMotorLeft = 3; // uController connection for left motor
unsigned char uCMotorRight = 2; // uController connection for right motor
unsigned char uCButton1 = 10;
unsigned char uCArmA = 8; // uController connection for armA
unsigned char uCArmB = 1; // uController connection for armB
// Radio Channels and their behavior
unsigned char channelMove = 2; // Radio channel used for move;
unsigned char channelRotate = 1; // Radion channel used for rotate;
unsigned char channelArmA = 3; // Radio channel used for armA;
unsigned char channelArmB = 5; // Radio channel used for armB;
// Position, speed, state variables
unsigned char button1 = 1; // Button changes state from radio to <other>
unsigned char armASpeed = 0; // Value for arm #1 position
unsigned char armBPos = 127;
while ( 1 )
{
unsigned char c5 = 127;
unsigned char c3 = 127;
// Use the "canned" one stick maneuvering
Arcade2(1, channelMove, channelRotate, uCMotorLeft, uCMotorRight, 1, 1);
// Get transmitter value for arm joint A
c3 = GetRxInput(1, channelArmA);
// Joint A uses geared-down motor, so run forward or back
// Provide a "dead" range from 117 to 137 otherwise use value as-is.
if(c3 > 137) {
armASpeed = c3;
} else if(c3 < 117) {
armASpeed = c3;
} else {
armASpeed = 127;
}
// Get transmitter value for arm joint B
c5 = GetRxInput(1, channelArmB);
// Joint B is a claw utilizing a servo motor.
// Controlled with button on back of transmitter.
// Set position to open/closed depending on button state.
if(c5 > 137) {
armBPos = 255;
} else {
armBPos = 0;
}
SetPWM(uCArmA, armASpeed);
SetPWM(uCArmB, armBPos);
}
}
Last edited by GlennGraham : 10-04-2006 at 20:42. |
|
#5
|
|||
|
|||
|
Re: Programming: MotorRcControl() vs GetRxInput()/SetServo()
Quote:
Are you using V1? If so, look at the help because I think the correct use is described there. But if you are, I'd suggest tryng to upgrade to V2 since it has some nice extra features (like user functions) and all that stuff is cleaned up. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming Vex w/ MPLab | dababyjebus | FIRST Tech Challenge | 27 | 25-04-2008 09:11 |
| Programming - Getting Started | Mark McLeod | Programming | 80 | 16-04-2008 23:37 |
| VEX programming | Gene F | Programming | 14 | 08-08-2006 22:21 |
| Programming Forum Warning | Brandon Martus | Announcements | 10 | 29-12-2005 13:32 |
| Robot Programming Education | phrontist | Programming | 11 | 03-05-2004 07:32 |