View unanswered posts | View active topics It is currently Mon Jul 15, 2019 6:36 pm






Reply to topic  [ 4 posts ] 
nMotorEncoder[] cannot have a non-zero value written to it 
Author Message
Rookie

Joined: Sun Nov 30, 2014 7:58 pm
Posts: 2
Post nMotorEncoder[] cannot have a non-zero value written to it
We have a need to keep track of the encoder count between autonomous and teleop on a motor. In the autonomous program, we wrote the encoder value to a file each time we moved the motor. Then in the teleop program we opened this file, and attempted to set the encoder to the last written value. However, this does not work. Apparently RobotC only allows you to write a 0 to the encoder.

Please fix this problem, as it is causing us to have to home a motor in teleop init function, which is apparently discouraged. Only servos are supposed to be moved in the init function.



Here is an example program that demonstrates how writing the encoder to a non-zero value fails:

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  HTServo)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     M1,            tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     Shoot,         tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C2_1,     Scissor,       tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     M3,            tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C3_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C3_6,    servo6,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_1,    servo7,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_2,    servo8,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_3,    servo9,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_4,    servo10,              tServoNone)
#pragma config(Servo,  srvo_S1_C4_5,    servo11,              tServoNone)
#pragma config(Servo,  srvo_S1_C4_6,    servo12,              tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
#pragma DebuggerWindows("debugStream")

task main()
{

   clearDebugStream();

   // Print out the motor encoder value
   writeDebugStream("Motor Encoder:%d\n",nMotorEncoder[Shoot]);

   // Now Try to set the motor encoder to some non-zero value
   nMotorEncoder[Shoot]=1120;

   wait1Msec(250);

  // Print out the motor encoder value
   writeDebugStream("Motor Encoder:%d\n",nMotorEncoder[Shoot]);


}



GregGarner


Sun Nov 30, 2014 8:25 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: nMotorEncoder[] cannot have a non-zero value written to
Could you just use the stored encoder value as some kind of offset? I don't think the ability to set encoders to non-zero values is coming to ROBOTC any time in the near future (if ever), so you'll need some kind of other way to do it.

By the way, homing a motor in the teleop init function is not only discouraged, it is illegal. Your robot will not pass field inspection if a motor moves between the end of autonomous and the start of teleop.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Sun Nov 30, 2014 11:32 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 620
Post Re: nMotorEncoder[] cannot have a non-zero value written to
This is a design intent. The motor encoder data (especially with TETRIX) just comes back as an I2C register read. We are unable to write data into this register - only simple set another register to have it "reset".

As previously mentioned, you could allocated your own variable/data to remember encoder data between "resets" and use that offset value to achieve what you're looking to accomplish.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Tue Dec 02, 2014 5:31 pm
Profile
Rookie

Joined: Sun Nov 30, 2014 7:58 pm
Posts: 2
Post Re: nMotorEncoder[] cannot have a non-zero value written to
It is unfortunate that the hardware does not allow setting the encoder to a non-zero value.

I did the offset thing, but in my opinion it would be a much cleaner system to allow writing the encoder to a non-zero value.

In my opinion The interface you have is inconsistent and confusing.
The format of the command nMotorEncoder[x] = Y implies that you can set it to something other than zero.
Even the help for the command implies that you can set it to any value, and there is no mention that you are restricted to setting it to zero.

If we were writing the interface from scratch, it would have been better to have a system call like ClearEncoder(x) rather than the format you have now. Clearly it is too late to change it.

However, it is not too late to change the documentation to make it clear that the only allowed option is to clear the encoder, so the next guy trying to do this doesn't spend a lot of time trying to write the encoder to a non-zero value. If possible, please make this change.

Having this (hardware) limitation makes code much harder to understand and to maintain, whereas allowing non-zero setting makes things very clear and easy.
It is quite common for robots to have motor actuators that have encoders, and given that the rules do not allow us to move the motors between autonomous and teleop, the only other choice is to find some mechanism to not lose the encoder value when the system resets the encoders to zero between the two programs.
Disallowing the option to set the encoder back to the last value just makes the RobotC programmers life harder.

Given that it is a hardware limitation, I will just have to live with it.
If anyone ever redesigns the hardware, then it is my fervent wish that they will take this request under advisement.

Greg Garner


Tue Dec 02, 2014 5:41 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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:  
cron



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