Functions | |
| void | pwm_set (unsigned char port, char val) |
| char | pwm_get (unsigned char port) |
| void | master_submit_data (unsigned char wait) |
| void | master_set_user_cmd (unsigned char cmd) |
| void | master_clr_user_cmd (unsigned char cmd) |
| void master_clr_user_cmd | ( | unsigned char | cmd | ) |
Clear bits in the user command to be sent to the master processor. The update will not be transmitted to the master processor until master_submit_data() is called. See master.h for possible values.
| void master_set_user_cmd | ( | unsigned char | cmd | ) |
Set bits in the user command to be sent to the master processor. The update will not be transmitted to the master processor until master_submit_data() is called. See master.h for possible values.
| void master_submit_data | ( | unsigned char | wait | ) |
Buffer PWM data, etc. to be sent to the master processor.
This function must be called following other master_*() and pwm_*() functions in order to send the updates to the master processor. This allows multiple PWMs to be altered using separate pwm_set() calls without actually changing the motor speeds at separate times. Instead, pwm_set() places changes in the buffer, and all changes are submitted together by master_submit_data(), so that motor speeds can all be changed (almost) simultaneously by the master processor.
This can also reduce load on the user processor caused by buffer management for each packet sent. Programmers are encouraged to make multiple changes via pwm_set() and master_*() functions before each expensive master_submit_data() call.
| wait | One of the manifest constants WAIT or NO_WAIT. Specifies whether or not to wait for data to reach master processor. |
If NO_WAIT, master_submit_data() returns immediately, and the data will be picked up by the master processor at an unknown time within the next 18.5 ms. This is the preferred method if it isn't critical when the submitted data takes effect, since it avoids burning up to 18.5 ms of CPU time that could be used for useful work.
Example: If you want a delay loop to begin after motors have actually started, to guarantee that the motors run for the full specified delay period:
pwm_set(LEFT_DRIVE_PORT, 50); pwm_set(RIGHT_DRIVE_PORT, -50); master_submit_data(WAIT); delay_msec(250);
Note that in many applications, it wouldn't matter much if the motors run for 231.5 ms instead of 250 ms, so NO_WAIT may be perfectly reasonable in the above example.
| char pwm_get | ( | unsigned char | port | ) |
| void pwm_set | ( | unsigned char | port, | |
| char | val | |||
| ) |
Set the PWM value for the specified port. Values range from -127 to 127. For motors, 0 means stop. For servos, 0 is the center position.
Changes made through this function will not take effect until master_submit_data() is called. It will then take between 0 and 18.5 ms before the submitted data reaches the master processor.
Motors and servos are controlled directly by the master processor. To alter a motor/servo setting, the following must occur:
1. call pwm_set(). This only alters the next packet to be sent.
2. call master_submit_data(). This queues the altered packet for sending to the master processor.
3. The master processor interrupts the user processor every 18.5 ms to send sample data from the RC unit and retrieve the latest data queued by master_submit_data().
Hence, motor setting will change between 0 and 18.5 ms after your code calls master_submit_data().
1.5.8