BEST Robotics Forum
Register Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
CollinC

Junior Member
Registered:
Posts: 4
Reply with quote  #1 
I have recently gotten into using RobotC, and it is really great! It is much more customizable than Easy-C. I have seen other teams make it so when they push the joystick all the way, the robot doesn't just jump to full speed, it eases into full speed to prevent any jumpiness. How can I achieve this in RobotC?
0
jgraber

Moderator
Registered:
Posts: 156
Reply with quote  #2 
In what ways do you find RobotC more customizable than EasyC?
There are many features of EasyC I am not yet using, but I know you can at least write your own C-code in any editor, save it, and press build and download in EasyC and it will load your updated file ok.

Your question relates to two topics;
 - gear shift or slow speed mode : changes joystick scale to smaller magnitude : eg full speed is -127 to +127,  half speed is -64 to +64
 - Slew control : reduce the rate of change of commands going to motors,  instead of allowing immediate change from 0 to 127, do 0, 10,20,30,40,50,60,..127 over some number of milliseconds.
Both RobotC and EasyC have similar solutions.  You have to discard the built-in commands like "arcade-mode", and write them yourself.

I use the term : SPA  for Sense, Plan, Act.
The built-in commands have no planning, just Sense and reAct, and have no stored values for history, or memory.
Sensing is reading the values of all the sensors and Joystick inputs into variables.
 Planning involves having a history or stored state of what you used to be doing, and might want to do in the future.
Acting is just doing SetMotor commands to values determined by planning.

So the first step is to convert your program from built-in arcade/tank mode, to SPA.
 joyx,joyy = getjoystick x,y; // Sense
myarcade(inputs: joyx, joyy; outputs: LeftM, RightM); // Plan,  convert x,y to values to send to Left/Right wheel motors
SetMotor( L,R); // Act,  Send the values to the motors

Now that you have SPA, you can make the Planning more complicated.

For gear shift:
 - make a variable to remember what gear you are in (full or half or 1,2,3,4 etc).
 - set some joystick buttons to act as gear selectors, when pressed, they change the variable above.
 - take the joystick analog inputs, and scale them by the gear shift value before applying them to motors

For SlewRate control, one way I have seen;
  Keep 2 sets of variable,  one for actual motor power value, and another one for target motor power value.
Use an idle timer loop to move the actual motor power value one STEP towards target value.
Experiment to find out what STEP size, and what timer duration works.

Remember that on Cortex, your EasyC code is running on the slave processor, while the actual motor ports are controlled by the master processor,
and the master listens to the slave for a motor speed update only once every 10-30ms.     
  RobotC is almost the same, except the slave processor is running a p-code interpreter that implements a task-sharing system,
which is interpreting your RobotC program that was compiled to P code.
  The master motor update loop time is variable about 10-30ms and there is no way to synchronize your slave C code to the master loop time.
If you try a slew rate of 1 per 1ms, it will work about the same as a step of 5 every 5ms, and a little more smoothly than a step of 50 every 50ms.



0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.