Hills Road RoboCon has made available the —
sr.robot — module which is used to interface with the hardware. It handles all the low-level interactions so you don’t have to. To set the output power of output 0 of the first motor board to -30%, for example, you would simply write:
R.motors.m0.power = -30
-30 would be backwards (depending upon which way you wired up the motor) — 30% power in reverse.
To gain access to all of this functionality, all you need to do is write:
from sr.robot import *
…at the top of your code (before you use any of its functionality, basically). This imports the Student Robotics module that we’ve updated to interface with our hardware.
Then, within the
sr.robot module, there is a
Robot class that should be instantiated, as follows:
from sr.robot import * R = Robot()
R in this case), you then have access to the following attributes:
They can be used in your code just like the example above. Note that
servos are Python lists, and so should be accessed as such. Here are some examples:
R.motors.m0.power = 50 # WILL work, if motor 0 exists R.motors.m0.power = -20 # WILL work, if motor 1 exists R.motors.m0.power = 42 # WON'T WORK # the above is similar to the situation for and 'servos'
A number of examples in the documentation will assume you’ve instantiated the required
Robot class and have called it
R. From here in, if you see a
R.something, the requirement of the
sr.robot import line and the instantiation of
R is implicit.
OTHER ROBOT ATTRIBUTES
As well as the attributes listed above, the Robot class also has the following attributes, which you may find useful:
- The number of the zone that the robot is associated with. An integer from 0 to 3 inclusive.
CUSTOM ROBOT OBJECT INITIALISATION
Normally the Robot object is initialised with the following:
R = Robot()
However if you want to:
- customise your Ruggeduino firmware
- initialise some hardware or software before the start button is pressed
Then Robot initialisation can be broken up as follows (this example is equivalent to the previous code excerpt):
R = Robot.setup() # Setup phase. # Here you can configure hardware enumeration R.init() # Initialisation phase. # Here you can perform hardware/software initialisation before start R.wait_start()
During the setup phase, the Robot hardware is inaccessible. For example,
R.motors is unavailable since enumerations occurs in the
init function. In this phase you can configure how the Robot finds and configures hardware.
init call, all hardware is accessible. If you have any hardware which must be initialised before the start button is pressed, the initialisation phase is the time to do so.